diff --git a/app/build.gradle b/app/build.gradle index 83a8703..c47f9d4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,10 +8,13 @@ buildscript { } } apply plugin: 'com.android.application' +apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-android' apply plugin: 'io.fabric' repositories { maven { url 'https://maven.fabric.io/public' } + mavenCentral() } @@ -51,13 +54,14 @@ dependencies { implementation 'com.squareup.retrofit2:converter-gson:2.3.0' implementation 'com.android.support:support-v4:28.0.0' implementation 'com.android.support:support-vector-drawable:28.0.0' - annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' - implementation 'com.jakewharton:butterknife:8.8.1' implementation 'io.reactivex:rxandroid:1.2.1' implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' + //UI + implementation 'com.params.stepview:stepview:1.0.2' + //debug libs implementation 'com.facebook.stetho:stetho:1.4.2' implementation 'com.facebook.stetho:stetho-okhttp3:1.4.2' @@ -76,5 +80,7 @@ dependencies { implementation('com.crashlytics.sdk.android:crashlytics:2.9.3@aar') { transitive = true } + implementation 'org.idpass.mobile.api:idpass-mobile-api:0.0.2' + } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 27c1272..0258b90 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,9 +14,8 @@ android:roundIcon="@mipmap/ic_launcher" android:supportsRtl="true" android:theme="@style/AppTheme"> - + + @@ -24,12 +23,19 @@ + android:name=".login.LoginActivity" + android:exported="true" /> + android:name=".newstaff.NewStaffActivity" + android:windowSoftInputMode="adjustResize" /> + + + + + diff --git a/app/src/main/java/np/com/naxa/staffattendance/AttandanceStaffRecyclerAdapter.java b/app/src/main/java/np/com/naxa/staffattendance/AttandanceStaffRecyclerAdapter.java deleted file mode 100644 index 6fc136c..0000000 --- a/app/src/main/java/np/com/naxa/staffattendance/AttandanceStaffRecyclerAdapter.java +++ /dev/null @@ -1,55 +0,0 @@ -package np.com.naxa.staffattendance; - -import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CheckBox; - -import java.util.List; - -import np.com.naxa.staffattendance.pojo.AttendancePojo; - -/** - * Created by samir on 4/1/2018. - */ - -public class AttandanceStaffRecyclerAdapter extends RecyclerView.Adapter { - - private List staffList; - - public class MyViewHolder extends RecyclerView.ViewHolder { - CheckBox staffName ; - - public MyViewHolder(View view) { - super(view); - staffName = (CheckBox) view.findViewById(R.id.staff_recycler_list_item_check_box); - } - } - - - public AttandanceStaffRecyclerAdapter(List staffList) { - this.staffList = staffList; - } - - @Override - public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - View itemView = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.recyclerview_staff_list_item, parent, false); - - return new MyViewHolder(itemView); - } - - - - @Override - public void onBindViewHolder(MyViewHolder holder, int position) { - AttendancePojo attendancePOJO = staffList.get(position); - holder.staffName.setText(attendancePOJO.getStaffName()); - } - - @Override - public int getItemCount() { - return staffList.size(); - } -} \ No newline at end of file diff --git a/app/src/main/java/np/com/naxa/staffattendance/AttendanceFormEditActivity.java b/app/src/main/java/np/com/naxa/staffattendance/AttendanceFormEditActivity.java deleted file mode 100644 index d30736c..0000000 --- a/app/src/main/java/np/com/naxa/staffattendance/AttendanceFormEditActivity.java +++ /dev/null @@ -1,127 +0,0 @@ -package np.com.naxa.staffattendance; - -import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; -import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import np.com.naxa.staffattendance.pojo.AttendancePojo; - -public class AttendanceFormEditActivity extends AppCompatActivity { - - private List movieList = new ArrayList<>(); - private AttandanceStaffRecyclerAdapter mAdapter; - - - @BindView(R.id.staff_list_recycler_view) - RecyclerView staffListRecyclerView; - @BindView(R.id.fab_update_staff_attendance) - FloatingActionButton fabUpdateStaffAttendance; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_attendance_form_edit); - ButterKnife.bind(this); - - getAndSetDateToView(); - - initToolbar(); - - initRecyclerView(); - - } - - private void initToolbar() { - final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - toolbar.setTitle(getAndSetDateToView()); - setSupportActionBar(toolbar); - final ActionBar actionBar = getSupportActionBar(); - - if (actionBar != null) { -// actionBar.setHomeAsUpIndicator(R.color.colorAccent); - actionBar.setDisplayHomeAsUpEnabled(true); - } - } - - public String getAndSetDateToView() { - - final Calendar c = Calendar.getInstance(); - int yy = c.get(Calendar.YEAR); - int mm = c.get(Calendar.MONTH); - int dd = c.get(Calendar.DAY_OF_MONTH); - - // set current date into textview - return (new StringBuilder() - // Month is 0 based, just add 1 - .append(yy).append(" ").append("-").append(mm + 1).append("-") - .append(dd)).toString(); - } - - public void initRecyclerView() { - mAdapter = new AttandanceStaffRecyclerAdapter(movieList); - RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext()); - staffListRecyclerView.setLayoutManager(mLayoutManager); - staffListRecyclerView.setItemAnimator(new DefaultItemAnimator()); - staffListRecyclerView.setAdapter(mAdapter); - - prepareMovieData(); - } - - - private void prepareMovieData() { - AttendancePojo attendancePOJO = new AttendancePojo("2018-4-1", "1", "Ram", "Hari"); - movieList.add(attendancePOJO); - - attendancePOJO = new AttendancePojo("2018-4-1", "2", "Shyam", "Hari"); - movieList.add(attendancePOJO); - - attendancePOJO = new AttendancePojo("2018-4-1", "3", "Hari", "Hari"); - movieList.add(attendancePOJO); - - attendancePOJO = new AttendancePojo("2018-4-1", "4", "Sumit", "Hari"); - movieList.add(attendancePOJO); - - attendancePOJO = new AttendancePojo("2018-4-1", "5", "Samir", "Hari"); - movieList.add(attendancePOJO); - - attendancePOJO = new AttendancePojo("2018-4-1", "6", "Nishon", "Hari"); - movieList.add(attendancePOJO); - - attendancePOJO = new AttendancePojo("2018-4-1", "7", "Aashis", "Hari"); - movieList.add(attendancePOJO); - - attendancePOJO = new AttendancePojo("2018-4-1", "8", "Shree 1", "Hari"); - movieList.add(attendancePOJO); - - attendancePOJO = new AttendancePojo("2018-4-1", "9", "Shree 2", "Hari"); - movieList.add(attendancePOJO); - - attendancePOJO = new AttendancePojo("2018-4-1", "10", "Madan", "Hari"); - movieList.add(attendancePOJO); - - attendancePOJO = new AttendancePojo("2018-4-1", "11", "Krishna", "Hari"); - movieList.add(attendancePOJO); - - - mAdapter.notifyDataSetChanged(); - } - - - @OnClick(R.id.fab_update_staff_attendance) - public void onViewClicked() { -// Intent intent = new Intent(AttendanceFormEditActivity.this, MainActivity.class); -// startActivity(intent); - } -} diff --git a/app/src/main/java/np/com/naxa/staffattendance/StaffListAdapter.java b/app/src/main/java/np/com/naxa/staffattendance/StaffListAdapter.java index 06c9dba..fe2e2f6 100644 --- a/app/src/main/java/np/com/naxa/staffattendance/StaffListAdapter.java +++ b/app/src/main/java/np/com/naxa/staffattendance/StaffListAdapter.java @@ -38,7 +38,7 @@ public class StaffListAdapter extends RecyclerView.Adapter selectedStaffHashMap = new HashMap<>(); - StaffListAdapter(Context mContext, List staffList, boolean enablePersonSelection, List attedanceIds, OnStaffItemClickListener listener) { + public StaffListAdapter(Context mContext, List staffList, boolean enablePersonSelection, List attedanceIds, OnStaffItemClickListener listener) { this.mContext = mContext; this.staffList = staffList; this.filetredsitelist = staffList; @@ -68,7 +68,8 @@ public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int pos staffVH.rootLayout.setEnabled(enablePersonSelection); staffVH.staffName.setText(staff.getFirstName()); - staffVH.staffType.setText(staff.getTeamName()); + staffVH.staffPost.setText(staff.getDesignationLabel()); + staffVH.iconText.setVisibility(View.VISIBLE); staffVH.imgProfile.setImageResource(R.drawable.circle_blue); staffVH.iconText.setText(staff.getFirstName().substring(0, 1)); @@ -180,6 +181,7 @@ private void applyIconAnimation(StaffVH holder, int position, boolean shouldHigh holder.staffStatus.setText(holder.rootLayout.getContext().getString(R.string.attedance_absent)); + holder.rootLayout.setActivated(!shouldHightlight); holder.iconBack.setVisibility(View.GONE); resetIconYAxis(holder.iconFront); @@ -238,12 +240,13 @@ public ArrayList getSelectedStaffID() { public class StaffVH extends RecyclerView.ViewHolder { - private TextView staffName, staffStatus, siteAddress, sitePhone, staffType, sitePendingFormsNumber, site, iconText, timestamp, tvTagOfflineSite; + private TextView staffName, staffStatus, siteAddress, sitePhone, staffType, sitePendingFormsNumber, site, iconText, timestamp, tvTagOfflineSite,staffPost; private ImageView iconImp, imgProfile; private RelativeLayout iconContainer, iconBack, iconFront; private RelativeLayout rootLayout; private CardView card; + public StaffVH(View view) { super(view); card = view.findViewById(R.id.card_site_lst_row); @@ -254,6 +257,7 @@ public StaffVH(View view) { staffStatus = view.findViewById(R.id.staff_list_row_status); staffName = view.findViewById(R.id.staff_list_row_name); + staffPost = view.findViewById(R.id.staff_list_row_post); siteAddress = view.findViewById(R.id.staff_list_row_email); sitePhone = view.findViewById(R.id.staff_list_row_phone); staffType = view.findViewById(R.id.staff_list_row_type); diff --git a/app/src/main/java/np/com/naxa/staffattendance/TeamRemoteSource.java b/app/src/main/java/np/com/naxa/staffattendance/TeamRemoteSource.java index e99e7a7..81d4c5b 100644 --- a/app/src/main/java/np/com/naxa/staffattendance/TeamRemoteSource.java +++ b/app/src/main/java/np/com/naxa/staffattendance/TeamRemoteSource.java @@ -157,8 +157,8 @@ public ArrayList call(ArrayList myTeamResponses) teamMemberResposne.setTeamID(myTeamResponse.getId()); teamMemberResposne.setTeamName(myTeamResponse.getName()); - StaffDao.getInstance().saveStaff(teamMemberResposne); - + long status = StaffDao.getInstance().saveStaff(teamMemberResposne); + Timber.d("Staff insert status %s", status); }) .toList()); diff --git a/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/AddItemButton.kt b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/AddItemButton.kt new file mode 100644 index 0000000..9e77972 --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/AddItemButton.kt @@ -0,0 +1,5 @@ +package np.com.naxa.staffattendance.attedancedashboard + +import np.com.naxa.staffattendance.attedancedashboard.base.IRow + +data class AddItemButton(val uuid: String) : IRow diff --git a/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/AttedanceBottomFragment.kt b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/AttedanceBottomFragment.kt new file mode 100644 index 0000000..db85460 --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/AttedanceBottomFragment.kt @@ -0,0 +1,111 @@ +package np.com.naxa.staffattendance.attedancedashboard + +import android.content.Context +import android.os.Bundle +import android.support.annotation.Nullable +import android.view.ViewGroup +import android.view.LayoutInflater +import android.support.design.widget.BottomSheetDialogFragment +import android.view.View +import kotlinx.android.synthetic.main.fragment_take_attedance_dialog.view.* +import np.com.naxa.staffattendance.R +import np.com.naxa.staffattendance.attendence.AttendanceResponse +import np.com.naxa.staffattendance.attendence.TeamMemberResposne +import np.com.naxa.staffattendance.common.IntentConstants +import np.com.naxa.staffattendance.database.AttendanceDao +import java.util.* +import kotlin.concurrent.fixedRateTimer + + +class AttedanceBottomFragment : BottomSheetDialogFragment() { + + private lateinit var demoTimer: Timer + var staff: TeamMemberResposne? = null + var statusDesc: Array? = null + var loadedDate: String? = null + lateinit var listener: OnAttedanceTakenListener + + interface OnAttedanceTakenListener { + fun onAttedanceTaken(position: Int) + } + + + fun onClickListener(listener: OnAttedanceTakenListener){ + this.listener = listener + } + + override fun onAttach(context: Context?) { + super.onAttach(context) + arguments?.getSerializable(IntentConstants.EXTRA_OBJECT)?.let { + staff = it as TeamMemberResposne + } + arguments?.getString(IntentConstants.ATTENDANCE_DATE)?.let { + loadedDate = it; + } + + } + + @Nullable + override fun onCreateView(inflater: LayoutInflater, + @Nullable container: ViewGroup?, + @Nullable savedInstanceState: Bundle?): View? { + + + val view = inflater.inflate(R.layout.fragment_take_attedance_dialog, container, + false) + + view.tv_take_attedance_frag_staff_name.text = staff?.firstName + demoTimer = fixedRateTimer("timer", false, 1000, 1000) { + requireActivity().runOnUiThread { + goToNextStep(view) + } + } + statusDesc = resources.getStringArray(R.array.attedance_status_desc); + loadFirstMessage(view) + return view; + } + + override fun onDestroy() { + super.onDestroy() + demoTimer.cancel() + } + + private fun goToNextStep(view: View) { + val currentCount: Int = view.statusViewScroller.statusView.currentCount + if (currentCount < 4) { + setMessage(currentCount - 1, view) + view.statusViewScroller.statusView.currentCount = currentCount + 1 + + } else { + saveAttedance() + dismiss() + listener.onAttedanceTaken(1) + } + + } + + fun saveAttedance() { + val attendanceResponse = AttendanceResponse() + attendanceResponse.setAttendanceDate(loadedDate) + attendanceResponse.setStaffs(listOf(staff?.id)) + attendanceResponse.setStaffProofs(listOf("demo-attedance-proof"))//todo: add attendanceProofToUpload + attendanceResponse.dataSyncStatus = AttendanceDao.SyncStatus.FINALIZED + AttedanceLocalSource.instance.updateAttendance(loadedDate, attendanceResponse, staff?.teamID) + + } + + private fun loadFirstMessage(view: View) { + setMessage(0, view) + } + + private fun setMessage(currentCount: Int, view: View) { + view.tv_take_attedance_frag_desc.text = statusDesc?.get(currentCount) + } + + companion object { + + fun newInstance(): AttedanceBottomFragment { + return AttedanceBottomFragment() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/AttedanceLocalSource.kt b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/AttedanceLocalSource.kt new file mode 100644 index 0000000..efb54ee --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/AttedanceLocalSource.kt @@ -0,0 +1,31 @@ +package np.com.naxa.staffattendance.attedancedashboard + +import np.com.naxa.staffattendance.attendence.AttendanceResponse +import np.com.naxa.staffattendance.database.AttendanceDao + +class AttedanceLocalSource { + + val attedanceDao = AttendanceDao() + + companion object { + val instance = AttedanceLocalSource() + } + + + fun getAttendanceForDate(date: String?, new_attendance: AttendanceResponse, team_id: String?): AttendanceResponse? { + val oldAttendance = attedanceDao.getAttedanceByDate(team_id, date) + if (oldAttendance.presentStaffIds != null && oldAttendance.presentStaffIds.size > 0) { + oldAttendance.setStaffs(oldAttendance.presentStaffIds + new_attendance.presentStaffIds) + return oldAttendance + } + + return new_attendance + } + + fun updateAttendance(date: String?, new_attendance: AttendanceResponse, team_id: String?) { + val attendanceResponse = getAttendanceForDate(date, new_attendance, team_id) + val contentValues = attedanceDao.getContentValuesForAttedance(attendanceResponse) + attedanceDao.saveAttedance(contentValues) + } + +} \ No newline at end of file diff --git a/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/AttendanceDay.kt b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/AttendanceDay.kt new file mode 100644 index 0000000..7eec6f6 --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/AttendanceDay.kt @@ -0,0 +1,12 @@ +package np.com.naxa.staffattendance.attedancedashboard + +import np.com.naxa.staffattendance.attedancedashboard.base.IRow + +data class AttendanceDay(val dayOfWeek: String, + val dayOfMonth: String, + val date: String, + val absentNoOfStaff: String, + val presentNoOfStaff: String, + val teamId: String, + val teamName: String, + val fullDate: String) : IRow \ No newline at end of file diff --git a/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/AttendancesDashboardActivity.kt b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/AttendancesDashboardActivity.kt new file mode 100644 index 0000000..e0cc599 --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/AttendancesDashboardActivity.kt @@ -0,0 +1,197 @@ +package np.com.naxa.staffattendance.attedancedashboard + +import android.app.ProgressDialog +import android.content.Context +import android.content.Intent +import android.os.Bundle +import android.os.Handler +import android.support.v7.app.AppCompatActivity +import android.support.v7.widget.DefaultItemAnimator +import android.support.v7.widget.GridLayoutManager +import android.support.v7.widget.LinearLayoutManager +import android.view.Menu +import android.view.MenuItem +import kotlinx.android.synthetic.main.activity_dashboard_attedance.* +import np.com.naxa.staffattendance.R +import np.com.naxa.staffattendance.TeamRemoteSource +import np.com.naxa.staffattendance.attendence.AttendanceViewPagerActivity +import np.com.naxa.staffattendance.common.UIConstants +import np.com.naxa.staffattendance.database.StaffDao +import np.com.naxa.staffattendance.database.TeamDao +import np.com.naxa.staffattendance.settings.SettingsActivity +import np.com.naxa.staffattendance.utlils.DateConvertor +import np.com.naxa.staffattendance.utlils.DialogFactory +import np.com.naxa.staffattendance.utlils.NetworkUtils +import np.com.naxa.staffattendance.utlils.ToastUtils +import retrofit2.adapter.rxjava.HttpException +import rx.Observer +import rx.android.schedulers.AndroidSchedulers +import rx.functions.Action0 +import rx.schedulers.Schedulers +import timber.log.Timber +import java.io.IOException +import java.net.SocketTimeoutException +import java.util.concurrent.TimeUnit + + +class AttendancesDashboardActivity : AppCompatActivity() { + + private var exitOnBackPress: Boolean = false; + private val backPressHandler = Handler() + private val runnable = { exitOnBackPress = false } + + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_dashboard_attedance); + DialogFactory.createProgressDialogHorizontal(this@AttendancesDashboardActivity, "Please Wait") + setSupportActionBar(toolbar) + supportActionBar?.title = "" + setupListAdapter(generateGridItems()) + setupSwipeToRefresh() + + + } + + private fun setupSwipeToRefresh() { + swiperefresh.setOnRefreshListener { + if (NetworkUtils.isInternetAvailable()) { + TeamRemoteSource.getInstance() + .syncAll() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .doOnSubscribe(Action0 { this.showPleaseWaitDialog() }) + .subscribe(object : Observer { + override fun onCompleted() { + closePleaseWaitDialog() + showMessage("Everything is Up-to-date") + Timber.i("onCompleted") + } + + override fun onError(e: Throwable) { + closePleaseWaitDialog() + if (e is HttpException) { + try { + val responseBody = e.response().errorBody() + showMessage(responseBody!!.string()) + } catch (e1: NullPointerException) { + showMessage("") + e1.printStackTrace() + } catch (e1: IOException) { + showMessage("") + e1.printStackTrace() + } + + } else if (e is SocketTimeoutException) { + showMessage("Server took too long to respond") + } else if (e is IOException) { + showMessage(e.message.toString()) + } else { + showMessage(e.message.toString()) + } + } + + override fun onNext(o: Any) { + + } + }) + + } else { + ToastUtils.showLong(getString(R.string.no_internet)) + } + } + } + + private fun showPleaseWaitDialog() { + swiperefresh.isRefreshing = true; + } + + private fun showMessage(message: String) { + ToastUtils.showLong(message) + swiperefresh.isRefreshing = false; + } + + private fun closePleaseWaitDialog() { + swiperefresh.isRefreshing = false; + } + + private fun generateGridItems(): ArrayList { + val teamId = TeamDao().oneTeamIdForDemo + val list = arrayListOf() + var teamName: String = "" + val staffs = StaffDao().getStaffByTeamId(teamId) + list.add(getString(R.string.title_team)) + list.add("") + if (staffs.size > 0) { + teamName = staffs[0].teamName + val teamMembersCount = staffs.count().toString() + list.add(TeamStats(teamName, teamMembersCount)) + } + list.add(AddItemButton(UIConstants.UUID_GRID_ITEM_TEAM_MEMBER)) + list.add(getString(R.string.title_attedance)) + list.add("") + + + for (x in 1 downTo -6 step 1) { + val date = DateConvertor.getPastDate(x) + val yearMonthDay = DateConvertor.getYearMonthDay(date); + list.add(element = AttendanceDay(dayOfWeek = yearMonthDay[2], + dayOfMonth = yearMonthDay[1], + date = yearMonthDay[0], + absentNoOfStaff = "", + presentNoOfStaff = "", + teamId = teamId, + teamName = teamName, + fullDate = DateConvertor.formatDate(DateConvertor.getDateForPosition(x)))); + } + + return list; + } + + override fun onCreateOptionsMenu(menu: Menu?): Boolean { + menuInflater.inflate(R.menu.menu_dashboard, menu); + return super.onCreateOptionsMenu(menu) + } + + override fun onOptionsItemSelected(item: MenuItem?): Boolean { + when (item?.itemId) { + R.id.main_dashboard_setting -> { + val toSettings = SettingsActivity.newIntent(this@AttendancesDashboardActivity) + startActivity(toSettings) + } + } + return super.onOptionsItemSelected(item) + } + + + override fun onBackPressed() { + if (exitOnBackPress) { + finish() + return + } + + exitOnBackPress = true + ToastUtils.showShort(getString(R.string.msg_backpress_to_exit)) + backPressHandler.postDelayed(runnable, TimeUnit.SECONDS.toMillis(2)) + } + + private fun setupListAdapter(days: List) { + + val manager = LinearLayoutManager(this) + recycler_view.setLayoutManager(manager) + recycler_view.setItemAnimator(DefaultItemAnimator()) + recycler_view.apply { + layoutManager = GridLayoutManager(this@AttendancesDashboardActivity, 2) + adapter = ListAdapter(days) + } + recycler_view.addItemDecoration(ItemOffsetDecoration(this, R.dimen.spacing_small)) + + } + + companion object { + fun newIntent(context: Context): Intent { + val intent = Intent(context, AttendancesDashboardActivity::class.java) + return intent + } + } +} \ No newline at end of file diff --git a/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/BaseRecyclerViewAdapter.java b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/BaseRecyclerViewAdapter.java new file mode 100644 index 0000000..97a55da --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/BaseRecyclerViewAdapter.java @@ -0,0 +1,54 @@ +package np.com.naxa.staffattendance.attedancedashboard; + +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import java.util.List; + +import np.com.naxa.staffattendance.application.StaffAttendance; +import timber.log.Timber; + + +//import com.rillmark.royalworldcup.MainApplication; + +public abstract class BaseRecyclerViewAdapter extends RecyclerView.Adapter { + private List l; + private int layout; + + protected BaseRecyclerViewAdapter(List l, int layout) { + this.l = l; + this.layout = layout; + Timber.d("listSize = %s", l.size()); + } + + @NonNull + @Override + public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(StaffAttendance.getStaffAttendance()).inflate(layout, parent, false); + return attachViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull VH holder, int position) { + viewBinded(holder, l.get(position)); + } + + public List getData() { + return this.l; + } + + @Override + public int getItemCount() { + return l.size(); + } + + public abstract void viewBinded(VH vh, L l); + + public abstract VH attachViewHolder(View view); + + + +} \ No newline at end of file diff --git a/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/CalendraVH.kt b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/CalendraVH.kt new file mode 100644 index 0000000..013f86d --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/CalendraVH.kt @@ -0,0 +1,55 @@ +package np.com.naxa.staffattendance.attedancedashboard + +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import np.com.naxa.staffattendance.R +import np.com.naxa.staffattendance.attendence.v2.AttedanceActivity +import np.com.naxa.staffattendance.database.TeamDao + + +class CalendarVH(inflater: LayoutInflater, parent: ViewGroup) : + RecyclerView.ViewHolder(inflater.inflate(R.layout.grid_item_calendra, parent, false)) { + private var tvDay: TextView? = null + private var tvDate: TextView? = null + private var tvMonthYear: TextView? = null + private var tvAbsentMessage: TextView? = null + private var tvPresentMessage: TextView? = null + private var rootLayout: View? = null + + + init { + tvDay = itemView.findViewById(R.id.tv_day) + tvDate = itemView.findViewById(R.id.tv_date) + tvMonthYear = itemView.findViewById(R.id.tv_month_year) + tvAbsentMessage = itemView.findViewById(R.id.tv_absent_message) + tvPresentMessage = itemView.findViewById(R.id.tv_present_message) + rootLayout = itemView.findViewById(R.id.root_layout) + } + + fun bind(day: AttendanceDay) { + tvDay?.text = day.dayOfWeek + tvDate?.text = day.dayOfMonth + tvMonthYear?.text = day.date + rootLayout?.setOnClickListener { + var intent = AttedanceActivity.newIntent(itemView.context, date = day.fullDate, teamId = day.teamId, teamName = day.teamName) + itemView.context.startActivity(intent); + } + + } + + fun setAbsentPresentMessage(day: AttendanceDay) { + if (isNullOrEmpty(day.absentNoOfStaff)) { + + } + } + + + fun isNullOrEmpty(str: String?): Boolean { + if (str != null && !str.isEmpty()) + return false + return true + } +} \ No newline at end of file diff --git a/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/HeaderVH.kt b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/HeaderVH.kt new file mode 100644 index 0000000..c93f699 --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/HeaderVH.kt @@ -0,0 +1,24 @@ +package np.com.naxa.staffattendance.attedancedashboard + + + +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.TextView +import np.com.naxa.staffattendance.R + + +class HeaderVH(inflater: LayoutInflater, parent: ViewGroup) : + RecyclerView.ViewHolder(inflater.inflate(R.layout.header, parent, false)) { + private var tvHeaderTitle: TextView? = null + + init { + tvHeaderTitle = itemView.findViewById(R.id.tv_header_title) + } + + fun bind(title: String) { + tvHeaderTitle?.text = title + } + +} \ No newline at end of file diff --git a/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/ItemOffsetDecoration.kt b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/ItemOffsetDecoration.kt new file mode 100644 index 0000000..2f891af --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/ItemOffsetDecoration.kt @@ -0,0 +1,19 @@ +package np.com.naxa.staffattendance.attedancedashboard + +import android.content.Context +import android.graphics.Rect +import android.support.annotation.DimenRes +import android.support.v7.widget.RecyclerView +import android.view.View + + +class ItemOffsetDecoration(private val mItemOffset: Int) : RecyclerView.ItemDecoration() { + + constructor(context: Context, @DimenRes itemOffsetId: Int) : this(context.getResources().getDimensionPixelSize(itemOffsetId)) {} + + override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, + state: RecyclerView.State) { + super.getItemOffsets(outRect, view, parent, state) + outRect.set(mItemOffset, mItemOffset, mItemOffset, mItemOffset) + } +} \ No newline at end of file diff --git a/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/ListAdapter.kt b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/ListAdapter.kt new file mode 100644 index 0000000..73baf9c --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/ListAdapter.kt @@ -0,0 +1,77 @@ +package np.com.naxa.staffattendance.attedancedashboard + +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater +import android.view.ViewGroup +import np.com.naxa.staffattendance.attedancedashboard.base.AddItemVH + + +class ListAdapter(private val list: List) + : RecyclerView.Adapter() { + + private val TYPE_CONTENT = 0 + private val TYPE_ADD_CONTENT = 1 + private val TYPE_HEADER = 2 + private val TYPE_STATS = 3 + + + override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { + when (holder.itemViewType) { + TYPE_ADD_CONTENT -> onBindAddItem(holder as AddItemVH, list[position] as AddItemButton) + TYPE_CONTENT -> onBindContent(holder as CalendarVH, list[position] as AttendanceDay) + TYPE_HEADER -> onBindHeader(holder as HeaderVH, list[position] as String) + TYPE_STATS -> onBindTeamStats(holder as TeamStatsVH, list[position] as TeamStats) + + else -> throw IllegalArgumentException() + } + } + + private fun onBindTeamStats(teamStatsVH: TeamStatsVH, teamStats: TeamStats) { + teamStatsVH.bind(teamStats) + } + + + private fun onBindHeader(headerVH: HeaderVH, s: String) { + headerVH.bind(s); + } + + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + val inflater = LayoutInflater.from(parent.context) + when (viewType) { + TYPE_ADD_CONTENT -> return AddItemVH(inflater, parent) + TYPE_CONTENT -> return CalendarVH(inflater, parent) + TYPE_HEADER -> return HeaderVH(inflater, parent) + TYPE_STATS -> return TeamStatsVH(inflater, parent) + else -> throw IllegalArgumentException() + } + + } + + + private fun onBindAddItem(holder: AddItemVH, row: AddItemButton) { + holder.bind(row); + } + + private fun onBindContent(holder: CalendarVH, row: AttendanceDay) { + holder.bind(row); + } + + override fun getItemViewType(position: Int): Int { + return when (list[position]) { + is AttendanceDay -> TYPE_CONTENT + is AddItemButton -> TYPE_ADD_CONTENT + is String -> TYPE_HEADER + is TeamStats -> TYPE_STATS + + else -> throw IllegalArgumentException() + } + } + + override fun getItemCount(): Int = list.size +} + + + + + diff --git a/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/TeamStats.kt b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/TeamStats.kt new file mode 100644 index 0000000..dd03e0d --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/TeamStats.kt @@ -0,0 +1,3 @@ +package np.com.naxa.staffattendance.attedancedashboard + +data class TeamStats(val teamName: String, val teamMembersCount: String) \ No newline at end of file diff --git a/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/TeamStatsVH.kt b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/TeamStatsVH.kt new file mode 100644 index 0000000..b7933ef --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/TeamStatsVH.kt @@ -0,0 +1,30 @@ +package np.com.naxa.staffattendance.attedancedashboard + +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import np.com.naxa.staffattendance.R + + +class TeamStatsVH(inflater: LayoutInflater, parent: ViewGroup) : + RecyclerView.ViewHolder(inflater.inflate(R.layout.grid_item_stats, parent, false)) { + + private var tvTeamName: TextView? = null + private var tvTeamMemberCount: TextView? = null + + + init { + tvTeamName = itemView.findViewById(R.id.tv_team_name) + tvTeamMemberCount = itemView.findViewById(R.id.tv_members_count) + + } + + fun bind(day: TeamStats) { + tvTeamName?.text = day.teamName + tvTeamMemberCount?.text = day.teamMembersCount + + } + +} \ No newline at end of file diff --git a/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/base/AddItemVH.kt b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/base/AddItemVH.kt new file mode 100644 index 0000000..3ec80d2 --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/base/AddItemVH.kt @@ -0,0 +1,34 @@ +package np.com.naxa.staffattendance.attedancedashboard.base + + +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import np.com.naxa.staffattendance.R +import np.com.naxa.staffattendance.attedancedashboard.AddItemButton +import np.com.naxa.staffattendance.attedancedashboard.AttendanceDay +import np.com.naxa.staffattendance.common.UIConstants +import np.com.naxa.staffattendance.newstaff.NewStaffActivity +import np.com.naxa.staffattendance.utlils.ToastUtils + + +class AddItemVH(inflater: LayoutInflater, parent: ViewGroup) : + RecyclerView.ViewHolder(inflater.inflate(R.layout.grid_item_add, parent, false)) { + + + + fun bind(addItem: AddItemButton) { + + itemView.setOnClickListener { + when(addItem.uuid){ + UIConstants.UUID_GRID_ITEM_TEAM_MEMBER ->{ + NewStaffActivity.start(itemView.context,true); + } + } + } + + } + +} \ No newline at end of file diff --git a/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/base/base.kt b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/base/base.kt new file mode 100644 index 0000000..a84baa7 --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/attedancedashboard/base/base.kt @@ -0,0 +1,9 @@ +package np.com.naxa.staffattendance.attedancedashboard.base + +import android.support.v7.widget.RecyclerView +import android.view.View +import android.widget.TextView +import np.com.naxa.staffattendance.R + +interface IRow + diff --git a/app/src/main/java/np/com/naxa/staffattendance/attendence/TeamMemberResposne.java b/app/src/main/java/np/com/naxa/staffattendance/attendence/TeamMemberResposne.java index 3125af2..e250a3b 100644 --- a/app/src/main/java/np/com/naxa/staffattendance/attendence/TeamMemberResposne.java +++ b/app/src/main/java/np/com/naxa/staffattendance/attendence/TeamMemberResposne.java @@ -3,7 +3,9 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; -public class TeamMemberResposne { +import java.io.Serializable; + +public class TeamMemberResposne implements Serializable { private String teamID; private String teamName; @@ -60,6 +62,10 @@ public class TeamMemberResposne { @Expose private Object bank; + @SerializedName("designation_label") + private String designationLabel; + + public String getId() { return id; } @@ -77,7 +83,10 @@ public String getTeamID() { } - public TeamMemberResposne(String teamID, String teamName, String id, String firstName, String lastName, Object email, Integer gender, String ethnicity, String address, String phoneNumber, String bankName, String accountNumber, String photo, Integer designation, Object dateOfBirth, Object contractStart, Object contractEnd, Object bank, String IDPassDID) { + public TeamMemberResposne(String teamID, String teamName, String id, String firstName, String lastName, + Object email, Integer gender, String ethnicity, String address, String phoneNumber, + String bankName, String accountNumber, String photo, Integer designation, Object dateOfBirth, + Object contractStart, Object contractEnd, Object bank, String IDPassDID, String designationLabel) { this.teamID = teamID; this.teamName = teamName; this.id = id; @@ -96,9 +105,14 @@ public TeamMemberResposne(String teamID, String teamName, String id, String firs this.contractStart = contractStart; this.contractEnd = contractEnd; this.bank = bank; + this.designationLabel = designationLabel; this.IDPassDID = IDPassDID; } + public String getDesignationLabel() { + return designationLabel; + } + public String getIDPassDID() { return IDPassDID; diff --git a/app/src/main/java/np/com/naxa/staffattendance/attendence/TeamMemberResposneBuilder.java b/app/src/main/java/np/com/naxa/staffattendance/attendence/TeamMemberResposneBuilder.java index 25471a8..3e84776 100644 --- a/app/src/main/java/np/com/naxa/staffattendance/attendence/TeamMemberResposneBuilder.java +++ b/app/src/main/java/np/com/naxa/staffattendance/attendence/TeamMemberResposneBuilder.java @@ -20,6 +20,7 @@ public class TeamMemberResposneBuilder { private Object contractEnd; private Object bank; private String IDPassDID; + private String designationLabel; public TeamMemberResposneBuilder setTeamID(String teamID) { this.teamID = teamID; @@ -116,7 +117,12 @@ public TeamMemberResposneBuilder setIDPassDID(String IDPassDID) { return this; } + public TeamMemberResposneBuilder setDesignationLabel(String designationLabel) { + this.designationLabel = designationLabel; + return this; + } + public TeamMemberResposne createTeamMemberResposne() { - return new TeamMemberResposne(teamID, teamName, id, firstName, lastName, email, gender, ethnicity, address, phoneNumber, bankName, accountNumber, photo, designation, dateOfBirth, contractStart, contractEnd, bank,IDPassDID); + return new TeamMemberResposne(teamID, teamName, id, firstName, lastName, email, gender, ethnicity, address, phoneNumber, bankName, accountNumber, photo, designation, dateOfBirth, contractStart, contractEnd, bank,IDPassDID,designationLabel); } } \ No newline at end of file diff --git a/app/src/main/java/np/com/naxa/staffattendance/attendence/v2/AttedanceActivity.kt b/app/src/main/java/np/com/naxa/staffattendance/attendence/v2/AttedanceActivity.kt new file mode 100644 index 0000000..ffe0977 --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/attendence/v2/AttedanceActivity.kt @@ -0,0 +1,175 @@ +package np.com.naxa.staffattendance.attendence.v2 + +import android.app.Activity +import android.app.AlertDialog +import android.content.Context +import android.content.DialogInterface +import android.content.Intent +import android.nfc.NfcAdapter +import android.os.Build +import android.os.Bundle +import android.support.v7.widget.DefaultItemAnimator +import android.support.v7.widget.LinearLayoutManager +import android.view.MenuItem +import kotlinx.android.synthetic.main.activity_dashboard_attedance.* +import np.com.naxa.staffattendance.R +import np.com.naxa.staffattendance.StaffListAdapter +import np.com.naxa.staffattendance.attedancedashboard.AttedanceBottomFragment +import np.com.naxa.staffattendance.attedancedashboard.AttedanceLocalSource +import np.com.naxa.staffattendance.attedancedashboard.ItemOffsetDecoration +import np.com.naxa.staffattendance.attendence.AttendanceResponse + +import np.com.naxa.staffattendance.attendence.TeamMemberResposne +import np.com.naxa.staffattendance.common.BaseActivity +import np.com.naxa.staffattendance.common.IntentConstants +import np.com.naxa.staffattendance.database.AttendanceDao +import np.com.naxa.staffattendance.database.StaffDao +import np.com.naxa.staffattendance.database.TeamDao +import np.com.naxa.staffattendance.utlils.DateConvertor +import np.com.naxa.staffattendance.utlils.ToastUtils +import org.idpass.mobile.api.IDPassConstants +import org.idpass.mobile.api.IDPassIntent + + +class AttedanceActivity : BaseActivity(), StaffListAdapter.OnStaffItemClickListener { + private val IDENTIFY_RESULT_INTENT = 1 + + override fun onStaffClick(pos: Int, staff: TeamMemberResposne?) { +0 + } + + override fun onStaffLongClick(pos: Int) { + } + + private var loadedDate: String? = null; + private lateinit var stafflistAdapter: StaffListAdapter + private var teamDao: TeamDao? = null + private var enablePersonSelection = true; + private var attedanceIds: List? = emptyList() + private lateinit var teamId: String + private lateinit var teamName: String + private lateinit var nfcAdapter: NfcAdapter + + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_dashboard_attedance) + loadedDate = intent.getStringExtra(IntentConstants.ATTENDANCE_DATE); + teamId = intent.getStringExtra(IntentConstants.TEAM_ID); + teamName = intent.getStringExtra(IntentConstants.TEAM_NAME); + +// val dailyAttendance = AttendanceDao().getAttedanceByDate(teamId, loadedDate) +// setAttendanceIds(dailyAttendance.presentStaffIds,dailyAttendance.getAttendanceDate(false)) + + setupToolbar(title = teamName) + setupRecyclerView() + swiperefresh.isEnabled = false + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + nfcAdapter = NfcAdapter.getDefaultAdapter(applicationContext) + } + } + + public override fun onResume() { + super.onResume() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + nfcAdapter.enableReaderMode(this, { tag -> + val intent = IDPassIntent.intentIdentify( + IDPassConstants.IDPASS_TYPE_MIFARE, + true, + true, + tag) + startActivityForResult(intent, IDENTIFY_RESULT_INTENT) + }, NfcAdapter.FLAG_READER_NFC_A or NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK, null) + } + } + + + public override fun onPause() { + super.onPause() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + nfcAdapter.disableReaderMode(this) + } + } + + + public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + + if (requestCode == IDENTIFY_RESULT_INTENT && resultCode == Activity.RESULT_OK) { + val signedActionBase64 = data!!.getStringExtra(IDPassConstants.IDPASS_SIGNED_ACTION_RESULT_EXTRA) + + val signedAction = IDPassIntent.signedActionBuilder(signedActionBase64) + + val idPassDID = signedAction.action.person.did + + val staffs = StaffDao().getStaffByIdPassDID(idPassDID) + if (staffs.size > 0) { + val staff = staffs[0] + saveAttendance(staff, signedActionBase64) + } + } + } + + fun saveAttendance(staff: TeamMemberResposne, signedAction: String) { + val attendanceResponse = AttendanceResponse() + attendanceResponse.setAttendanceDate(loadedDate) + attendanceResponse.setStaffs(listOf(staff.id)) + attendanceResponse.setStaffProofs(listOf(signedAction))//todo: add attendanceProofToUpload + attendanceResponse.dataSyncStatus = AttendanceDao.SyncStatus.FINALIZED + AttedanceLocalSource.instance.updateAttendance(loadedDate, attendanceResponse, staff.teamID) + + } + + override fun onOptionsItemSelected(item: MenuItem?): Boolean { + when (item?.itemId) { + android.R.id.home -> onBackPressed(); + } + return super.onOptionsItemSelected(item) + } + + + private fun setupRecyclerView() { + val teamDao = TeamDao() + val mLayoutManager = LinearLayoutManager(applicationContext) + val teamId = teamDao.oneTeamIdForDemo + attedanceIds = AttendanceDao().getAttedanceByDate(teamId, loadedDate).presentStaffIds + + val staffs = StaffDao().getStaffByTeamId(teamId) + stafflistAdapter = StaffListAdapter(this, staffs, enablePersonSelection, attedanceIds, this) + recycler_view.layoutManager = mLayoutManager + recycler_view.itemAnimator = DefaultItemAnimator() + recycler_view.adapter = stafflistAdapter + var count = recycler_view.itemDecorationCount + if (count == 0) { + recycler_view.addItemDecoration(ItemOffsetDecoration(this, R.dimen.spacing_small)) + } + } + + fun setAttendanceIds(attendanceIds: List?, attendanceDate: String) { + this.attedanceIds = attendanceIds + val isAttedanceEmpty = attendanceIds?.isEmpty() + val isAttedanceDateToday = DateConvertor.getCurrentDate().equals(attendanceDate, ignoreCase = true) + if (isAttedanceEmpty!! && isAttedanceDateToday) { + enablePersonSelection = true + } + + val isAttendenceNotEmpty = !isAttedanceEmpty + + if (isAttedanceDateToday && isAttendenceNotEmpty) { + enablePersonSelection = false + } + } + + + companion object { + fun newIntent(context: Context, date: String, teamId: String, teamName: String): Intent { + val intent = Intent(context, AttedanceActivity::class.java) + intent.putExtra(IntentConstants.ATTENDANCE_DATE, date); + intent.putExtra(IntentConstants.TEAM_ID, teamId); + intent.putExtra(IntentConstants.TEAM_NAME, teamName); + return intent + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/np/com/naxa/staffattendance/common/BaseActivity.kt b/app/src/main/java/np/com/naxa/staffattendance/common/BaseActivity.kt new file mode 100644 index 0000000..5cab93c --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/common/BaseActivity.kt @@ -0,0 +1,34 @@ +package np.com.naxa.staffattendance.common + +import android.os.Bundle +import android.support.v7.app.AppCompatActivity +import android.view.MenuItem +import kotlinx.android.synthetic.main.activity_dashboard_attedance.* +import np.com.naxa.staffattendance.R + +open class BaseActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + } + + protected fun setupToolbar(title: String) { + setSupportActionBar(toolbar) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + supportActionBar?.setDisplayShowTitleEnabled(false) + supportActionBar?.title = "" + supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_toolbar_back) + tv_screen_name.text = title + + } + + override fun onOptionsItemSelected(item: MenuItem?): Boolean { + when (item?.itemId) { + android.R.id.home -> onBackPressed(); + } + return super.onOptionsItemSelected(item) + } + + + +} diff --git a/app/src/main/java/np/com/naxa/staffattendance/common/Constant.kt b/app/src/main/java/np/com/naxa/staffattendance/common/Constant.kt new file mode 100644 index 0000000..32d8ddc --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/common/Constant.kt @@ -0,0 +1,18 @@ +package np.com.naxa.staffattendance.common + +object UIConstants { + const val UUID_GRID_ITEM_TEAM_MEMBER = "add_team_member" +} + + +object IntentConstants { + + const val ATTENDANCE_DATE = "attendance_date" + const val EXTRA_OBJECT = "extra_object" + const val TEAM_ID = "team_id" + const val TEAM_NAME = "team_name" +} + + +val KEY_LOGOUT = "logout" +val KEY_APP_UPDATE = "app_update" \ No newline at end of file diff --git a/app/src/main/java/np/com/naxa/staffattendance/database/DatabaseHelper.java b/app/src/main/java/np/com/naxa/staffattendance/database/DatabaseHelper.java index 1e97ff0..a326217 100644 --- a/app/src/main/java/np/com/naxa/staffattendance/database/DatabaseHelper.java +++ b/app/src/main/java/np/com/naxa/staffattendance/database/DatabaseHelper.java @@ -19,7 +19,9 @@ public class DatabaseHelper extends SQLiteOpenHelper { public static final String LOG = "DatabaseHelper"; // Database Version - public static final int DATABASE_VERSION = 6; + + public static final int DATABASE_VERSION = 7; + // Database Name public static final String DATABASE_NAME = "staffManager2"; @@ -43,6 +45,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { //New Staff Column names public static final String KEY_STAFF_DESIGNATION = "designation"; + public static final String KEY_STAFF_DESIGNATION_LABEL = "designation_label"; public static final String KEY_STAFF_FIRST_NAME = "first_name"; public static final String KEY_STAFF_LAST_NAME = "last_name"; public static final String KEY_STAFF_DOB = "dob"; @@ -77,6 +80,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { KEY_STAFF_TEAM_ID + " TEXT," +//todo if team will have more attr than name and id, make new team table KEY_STAFF_TEAM_NAME + " TEXT," + KEY_STAFF_FULL_NAME + " TEXT," + + KEY_STAFF_DESIGNATION_LABEL + " TEXT," + KEY_STAFF_TYPE + " INTEGER," + KEY_CREATED_BY + " INTEGER," + KEY_CREATED_AT + " DATETIME," + @@ -105,6 +109,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { KEY_ID + " INTEGER PRIMARY KEY," + KEY_ID_PASS + " TEXT ," + KEY_STAFF_DESIGNATION + " INTEGER," + + KEY_STAFF_DESIGNATION_LABEL + " TEXT," + KEY_STAFF_FIRST_NAME + " TEXT," + KEY_STAFF_LAST_NAME + " TEXT," + KEY_STAFF_DOB + " TEXT," + diff --git a/app/src/main/java/np/com/naxa/staffattendance/database/NewStaffDao.java b/app/src/main/java/np/com/naxa/staffattendance/database/NewStaffDao.java index 975f30f..46bc875 100644 --- a/app/src/main/java/np/com/naxa/staffattendance/database/NewStaffDao.java +++ b/app/src/main/java/np/com/naxa/staffattendance/database/NewStaffDao.java @@ -61,6 +61,7 @@ private NewStaffPojo mapCursorToPojo(Cursor cursor) { return new NewStaffPojoBuilder() .setDesignation(Integer.valueOf(DatabaseHelper.getStringFromCursor(cursor, DatabaseHelper.KEY_STAFF_DESIGNATION))) + .setDesignationLabel(DatabaseHelper.getStringFromCursor(cursor, DatabaseHelper.KEY_STAFF_DESIGNATION_LABEL)) .setFirstName(DatabaseHelper.getStringFromCursor(cursor, DatabaseHelper.KEY_STAFF_FIRST_NAME)) .setLastName(DatabaseHelper.getStringFromCursor(cursor, DatabaseHelper.KEY_STAFF_LAST_NAME)) .setDateOfBirth(DatabaseHelper.getStringFromCursor(cursor, DatabaseHelper.KEY_STAFF_DOB)) diff --git a/app/src/main/java/np/com/naxa/staffattendance/database/StaffDao.java b/app/src/main/java/np/com/naxa/staffattendance/database/StaffDao.java index 5951539..f92df61 100644 --- a/app/src/main/java/np/com/naxa/staffattendance/database/StaffDao.java +++ b/app/src/main/java/np/com/naxa/staffattendance/database/StaffDao.java @@ -70,11 +70,11 @@ public void saveStafflist(final List staffs) { private ContentValues getContentValuesFronSaff(TeamMemberResposne staff) { ContentValues contentValues = new ContentValues(); contentValues.put(DatabaseHelper.KEY_STAFF_FULL_NAME, staff.getFirstName().concat(" ").concat(staff.getLastName())); - contentValues.put(DatabaseHelper.KEY_STAFF_TYPE, StaffAttendance.getStaffAttendance().getString(R.string.not_avaliable, "Staff type")); contentValues.put(DatabaseHelper.KEY_ID, staff.getId()); contentValues.put(DatabaseHelper.KEY_STAFF_TEAM_ID, staff.getTeamID()); contentValues.put(DatabaseHelper.KEY_STAFF_TEAM_NAME, staff.getTeamName()); contentValues.put(DatabaseHelper.KEY_ID_PASS, staff.getIDPassDID()); + contentValues.put(DatabaseHelper.KEY_STAFF_DESIGNATION_LABEL, staff.getDesignationLabel()); return contentValues; } @@ -113,6 +113,7 @@ public ArrayList getStaffFromCursor(Cursor cursor) { String staffId = DatabaseHelper.getStringFromCursor(cursor, DatabaseHelper.KEY_ID); String staffName = DatabaseHelper.getStringFromCursor(cursor, DatabaseHelper.KEY_STAFF_FULL_NAME); String IDPassDID = DatabaseHelper.getStringFromCursor(cursor, DatabaseHelper.KEY_ID_PASS); + String designationLabel = DatabaseHelper.getStringFromCursor(cursor, DatabaseHelper.KEY_STAFF_DESIGNATION_LABEL); TeamMemberResposne staff = new TeamMemberResposneBuilder() .setTeamID(teamID) @@ -120,6 +121,7 @@ public ArrayList getStaffFromCursor(Cursor cursor) { .setId(staffId) .setIDPassDID(IDPassDID) .setFirstName(staffName) + .setDesignationLabel(designationLabel) .createTeamMemberResposne(); staffs.add(staff); diff --git a/app/src/main/java/np/com/naxa/staffattendance/database/TeamDao.java b/app/src/main/java/np/com/naxa/staffattendance/database/TeamDao.java index beb93dd..8701288 100644 --- a/app/src/main/java/np/com/naxa/staffattendance/database/TeamDao.java +++ b/app/src/main/java/np/com/naxa/staffattendance/database/TeamDao.java @@ -33,6 +33,7 @@ public Cursor getCursor(String selection, String[] selectionArgs) { return getCursor(false, selection, selectionArgs); } + public String getTeamNameById(String id) { String teamName = ""; Cursor cursor = null; diff --git a/app/src/main/java/np/com/naxa/staffattendance/login/LoginActivity.java b/app/src/main/java/np/com/naxa/staffattendance/login/LoginActivity.java index 9d5959e..63d3aa9 100644 --- a/app/src/main/java/np/com/naxa/staffattendance/login/LoginActivity.java +++ b/app/src/main/java/np/com/naxa/staffattendance/login/LoginActivity.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.support.design.widget.TextInputLayout; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.view.WindowManager; @@ -21,6 +22,7 @@ import np.com.naxa.staffattendance.FormCall; import np.com.naxa.staffattendance.R; import np.com.naxa.staffattendance.SharedPreferenceUtils; +import np.com.naxa.staffattendance.attedancedashboard.AttendancesDashboardActivity; import np.com.naxa.staffattendance.attendence.AttendanceViewPagerActivity; import np.com.naxa.staffattendance.attendence.MyTeamRepository; import np.com.naxa.staffattendance.data.APIClient; @@ -41,7 +43,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList private static final String TAG = "LoginActivity"; - private EditText tvUserName, tvPassword; + private TextInputLayout tvUserName, tvPassword; private Button btnLogin; private TokenMananger tokenMananger; private MyTeamRepository myTeamRepository; @@ -52,7 +54,6 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login_page); - getWindow().setBackgroundDrawableResource(R.drawable.login_background); if (TokenMananger.doesTokenExist()) { AttendanceViewPagerActivity.start(this, false); finish(); @@ -82,7 +83,7 @@ public void onClick(View view) { case R.id.btn_login: dialog = DialogFactory.createProgressDialogHorizontal(this, getString(R.string.msg_please_wait)); if (validate()) { - loginToServer(tvUserName.getText().toString(), tvPassword.getText().toString()); + loginToServer(tvUserName.getEditText().getText().toString(), tvPassword.getEditText().getText().toString()); } else { ToastUtils.showShort("Enter valid credentials.."); } @@ -218,11 +219,8 @@ private void fetchMyTeam() { @Override public void onCompleted() { dialog.dismiss(); - - AttendanceViewPagerActivity.start(LoginActivity.this, false); - finish(); - - + Intent intent = AttendancesDashboardActivity.Companion.newIntent(LoginActivity.this); + startActivity(intent); } @Override @@ -275,8 +273,8 @@ private boolean validate() { boolean valid = true; boolean ck = false; - String email = tvUserName.getText().toString(); - String password = tvPassword.getText().toString(); + String email = tvUserName.getEditText().getText().toString(); + String password = tvPassword.getEditText().getText().toString(); if (email.isEmpty()) { tvUserName.requestFocus(); @@ -286,7 +284,7 @@ private boolean validate() { ck = true; } - if (password.isEmpty() || password.length() < 4) { + if (password.isEmpty() ) { if (ck) { tvPassword.requestFocus(); } diff --git a/app/src/main/java/np/com/naxa/staffattendance/newstaff/NewStaffActivity.java b/app/src/main/java/np/com/naxa/staffattendance/newstaff/NewStaffActivity.java index 7857159..accfd42 100644 --- a/app/src/main/java/np/com/naxa/staffattendance/newstaff/NewStaffActivity.java +++ b/app/src/main/java/np/com/naxa/staffattendance/newstaff/NewStaffActivity.java @@ -8,13 +8,16 @@ import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; +import android.os.Handler; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.design.widget.BottomNavigationView; import android.support.design.widget.TextInputLayout; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; +import android.text.Editable; import android.text.TextUtils; +import android.text.TextWatcher; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; @@ -24,6 +27,7 @@ import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; +import android.widget.ScrollView; import android.widget.Spinner; import android.widget.TextView; @@ -41,6 +45,7 @@ import java.util.Calendar; import java.util.List; import java.util.Locale; +import java.util.Objects; import java.util.Random; import np.com.naxa.staffattendance.FormCall; @@ -49,6 +54,7 @@ import np.com.naxa.staffattendance.attendence.AttendanceViewPagerActivity; import np.com.naxa.staffattendance.attendence.TeamMemberResposne; import np.com.naxa.staffattendance.attendence.TeamMemberResposneBuilder; +import np.com.naxa.staffattendance.common.BaseActivity; import np.com.naxa.staffattendance.database.NewStaffDao; import np.com.naxa.staffattendance.database.StaffDao; import np.com.naxa.staffattendance.database.TeamDao; @@ -62,7 +68,7 @@ import rx.Observer; import timber.log.Timber; -public class NewStaffActivity extends AppCompatActivity implements View.OnClickListener, BottomNavigationView.OnNavigationItemSelectedListener { +public class NewStaffActivity extends BaseActivity implements View.OnClickListener, BottomNavigationView.OnNavigationItemSelectedListener { private int IDENTIFY_RESULT_INTENT = 1; private Spinner bank, designation; @@ -77,13 +83,14 @@ public class NewStaffActivity extends AppCompatActivity implements View.OnClickL private DatePickerDialog.OnDateSetListener date; private ArrayAdapter spinnerAdapter; private File photoFileToUpload; - private BottomNavigationView bottomNavigationView; + private Gson gson; private Dialog msgDialog; private TextView idpassValue; DatePickerDialog datePickerDialog; private String idPassDID; + private ScrollView scrollView; public static void start(Context context, boolean disableTrasition) { Intent intent = new Intent(context, NewStaffActivity.class); @@ -107,10 +114,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { initSpinners(); - bottomNavigationView.setSelectedItemId(R.id.action_add_staff); - bottomNavigationView.setOnNavigationItemSelectedListener(this); - - + setupToolbar("Add Staff"); } private void setFakeData() { @@ -290,8 +294,8 @@ private void initUI() { idpassEnroll = findViewById(R.id.idpass_enroll); save = findViewById(R.id.staff_save); create = findViewById(R.id.staff_send); - bottomNavigationView = (BottomNavigationView) - findViewById(R.id.bottom_navigation); + scrollView = findViewById(R.id.scrollView); + } private void initListeners() { @@ -400,37 +404,100 @@ private boolean validate() { boolean validation = false; if (designation.getSelectedItem().equals(getResources().getString(R.string.default_option))) { - ToastUtils.showShort("Select a designation"); + showErrorMessage(designation, "Select a designation"); } else if (firstName.getEditText().getText().toString().isEmpty()) { - ToastUtils.showShort("Enter first name"); + showErrorMessage(firstName, "Enter first name"); } else if (lastName.getEditText().getText().toString().isEmpty()) { - ToastUtils.showShort("Enter last name"); + showErrorMessage(lastName, "Enter last name"); } else if (dob.getText().toString().isEmpty()) { - ToastUtils.showShort("Choose date of birth"); + showErrorMessage(dob, "Choose date of birth"); } else if (gender.getCheckedRadioButtonId() == -1) { - ToastUtils.showShort("Select gender"); + showErrorMessage(gender, "Select Gender"); } else if (ethinicity.getEditText().getText().toString().isEmpty()) { - ToastUtils.showShort("Enter ethnicity"); + showErrorMessage(ethinicity, "Enter ethnicity"); } else if (bank.getSelectedItem().toString().equals(getResources().getString(R.string.default_option))) { - ToastUtils.showShort("Choose a option"); + showErrorMessage(bank, "Choose a bank"); } else if (bank.getSelectedItem().toString().equals(getResources().getString(R.string.bank_other)) && bankNameOther.getText().toString().isEmpty()) { - ToastUtils.showShort("Enter bank name"); + showErrorMessage(bankNameOther, "Enter Bank name"); } else if (!bank.getSelectedItem().toString().equals(getResources().getString(R.string.default_option)) && accountNumber.getEditText().getText().toString().isEmpty()) { - ToastUtils.showShort("Enter account number"); + showErrorMessage(accountNumber, "Enter Account number"); } else if (contactNumber.getEditText().getText().toString().isEmpty()) { - ToastUtils.showShort("Enter contact number"); + showErrorMessage(contactNumber, "Enter contact number"); } else if (address.getEditText().getText().toString().isEmpty()) { - ToastUtils.showShort("Enter address"); + showErrorMessage(address, "Enter address"); + } else if (contractStartDate.getText().toString().isEmpty()) { - ToastUtils.showShort("Choose contract start date"); + + showErrorMessage(contractEndDate, "Choose contract start date"); } else if (contractEndDate.getText().toString().isEmpty()) { - ToastUtils.showShort("Choose contract end date"); + + showErrorMessage(contractEndDate, "Choose contract end date"); + } else { validation = true; } return validation; } + private void focusOnView(final ScrollView scroll, final View view) { + new Handler().post(new Runnable() { + @Override + public void run() { + int vLeft = view.getLeft(); + int vRight = view.getRight(); + int sWidth = scroll.getWidth(); + scroll.smoothScrollTo(((vLeft + vRight - sWidth) / 2), 0); + } + }); + } + + private void showErrorMessage(View view, String errorMessage) { + + if (view instanceof EditText) { + ((EditText) view).setError(errorMessage); + Objects.requireNonNull(((EditText) view)).addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable s) { + ((TextInputLayout) view).setError(null); + } + }); + + } else if (view instanceof TextInputLayout) { + ((TextInputLayout) view).setError(errorMessage); + Objects.requireNonNull(((TextInputLayout) view).getEditText()).addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable s) { + ((TextInputLayout) view).setError(null); + } + }); + } else { + ToastUtils.showShort(errorMessage); + } + + focusOnView(scrollView, view); + + } + private void getDatePicker(final EditText view) { new DatePickerDialog(this, (view1, year, month, dayOfMonth) -> { @@ -466,6 +533,7 @@ public NewStaffPojo getNewStaffDetail() { .setPhoto(getPhotoLocation()) .setIDPass(idPassDID) .setStatus(NewStaffDao.SAVED) + .setDesignationLabel(designation.getSelectedItem().toString()) .createNewStaffPojo(); } @@ -511,7 +579,6 @@ private void idpassEnroll() { } - private void showImageOptionsDialog() { final CharSequence[] options = {"Take Photo", "Choose from Gallery", "Dismiss"}; @@ -564,7 +631,6 @@ public void onImagePicked(File photoFileToUpload, EasyImage.ImageSource source, @Override public void onBackPressed() { - AttendanceViewPagerActivity.start(this, false); finish(); } diff --git a/app/src/main/java/np/com/naxa/staffattendance/newstaff/NewStaffCall.java b/app/src/main/java/np/com/naxa/staffattendance/newstaff/NewStaffCall.java index 604b35d..22cffcc 100644 --- a/app/src/main/java/np/com/naxa/staffattendance/newstaff/NewStaffCall.java +++ b/app/src/main/java/np/com/naxa/staffattendance/newstaff/NewStaffCall.java @@ -2,25 +2,19 @@ import android.content.Context; -import android.net.Uri; -import android.support.v4.content.FileProvider; import java.io.File; -import np.com.naxa.staffattendance.AttendanceFormEditActivity; import np.com.naxa.staffattendance.application.StaffAttendance; import np.com.naxa.staffattendance.data.APIClient; import np.com.naxa.staffattendance.data.ApiInterface; import np.com.naxa.staffattendance.database.NewStaffDao; import np.com.naxa.staffattendance.database.TeamDao; import np.com.naxa.staffattendance.pojo.NewStaffPojo; -import np.com.naxa.staffattendance.utlils.ToastUtils; import okhttp3.MediaType; import okhttp3.MultipartBody; import okhttp3.RequestBody; -import retrofit2.Response; import rx.Observable; -import rx.Scheduler; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; diff --git a/app/src/main/java/np/com/naxa/staffattendance/pojo/NewStaffPojo.java b/app/src/main/java/np/com/naxa/staffattendance/pojo/NewStaffPojo.java index 7553492..5e01069 100644 --- a/app/src/main/java/np/com/naxa/staffattendance/pojo/NewStaffPojo.java +++ b/app/src/main/java/np/com/naxa/staffattendance/pojo/NewStaffPojo.java @@ -60,8 +60,15 @@ public class NewStaffPojo { private String status; + @SerializedName("designation_label") + private String designationLabel; + + + public NewStaffPojo(String id, Integer designation, String firstName, String lastName, String dateOfBirth, Integer gender, + String ethnicity, Integer bank, String bankName, String accountNumber, String phoneNumber, String email, + String address, String contractStart, String contractEnd, String photo, String status, String designationLabel, + String idPassDID) { - public NewStaffPojo(String id, Integer designation, String firstName, String lastName, String dateOfBirth, Integer gender, String ethnicity, Integer bank, String bankName, String accountNumber, String phoneNumber, String email, String address, String contractStart, String contractEnd, String photo, String status, String idPassDID) { this.id = id; this.firstName = firstName; this.lastName = lastName; @@ -79,9 +86,12 @@ public NewStaffPojo(String id, Integer designation, String firstName, String las this.contractEnd = contractEnd; this.bank = bank; this.status = status; + this.designationLabel = designationLabel; this.idPassDID = idPassDID; + } + public String getId() { return id; } @@ -218,7 +228,11 @@ public void setStatus(String status) { this.status = status; } - public String getIdPassDID() { return idPassDID; } + public String getIdPassDID() { + return idPassDID; + } - public void setIdPassDID(String idPassDID) { this.idPassDID = idPassDID; } + public void setIdPassDID(String idPassDID) { + this.idPassDID = idPassDID; + } } diff --git a/app/src/main/java/np/com/naxa/staffattendance/pojo/NewStaffPojoBuilder.java b/app/src/main/java/np/com/naxa/staffattendance/pojo/NewStaffPojoBuilder.java index 25995dc..7faf96f 100644 --- a/app/src/main/java/np/com/naxa/staffattendance/pojo/NewStaffPojoBuilder.java +++ b/app/src/main/java/np/com/naxa/staffattendance/pojo/NewStaffPojoBuilder.java @@ -18,8 +18,12 @@ public class NewStaffPojoBuilder { private String photo; private String status; private String id; + + private String designationLabel; + private String idPassDID; + public NewStaffPojoBuilder setDesignation(Integer designation) { this.designation = designation; return this; @@ -106,12 +110,21 @@ public NewStaffPojoBuilder setStatus(String status) { return this; } - public NewStaffPojoBuilder setIDPass(String idPassDID) { - this.idPassDID = idPassDID; + + public NewStaffPojoBuilder setDesignationLabel(String designationLabel) { + this.designationLabel = designationLabel; return this; } public NewStaffPojo createNewStaffPojo() { - return new NewStaffPojo(id, designation, firstName, lastName, dateOfBirth, gender, ethnicity, bank, bankName, accountNumber, phoneNumber, email, address, contractStart, contractEnd, photo, status, idPassDID); + return new NewStaffPojo(id, designation, firstName, lastName, dateOfBirth, gender, ethnicity, bank, bankName, accountNumber, phoneNumber, email, address, contractStart, contractEnd, photo, status, designationLabel, idPassDID); + } + + public NewStaffPojoBuilder setIDPass(String idPassDID) { + this.idPassDID = idPassDID; + return this; + } + + } \ No newline at end of file diff --git a/app/src/main/java/np/com/naxa/staffattendance/settings/AppInfoFragment.kt b/app/src/main/java/np/com/naxa/staffattendance/settings/AppInfoFragment.kt new file mode 100644 index 0000000..ef8b155 --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/settings/AppInfoFragment.kt @@ -0,0 +1,96 @@ +package np.com.naxa.staffattendance.settings + + +import android.content.Intent +import android.net.Uri +import android.os.Bundle +import android.preference.Preference +import android.preference.PreferenceFragment +import np.com.naxa.staffattendance.BuildConfig +import np.com.naxa.staffattendance.R +import np.com.naxa.staffattendance.SharedPreferenceUtils +import np.com.naxa.staffattendance.common.KEY_APP_UPDATE +import np.com.naxa.staffattendance.common.KEY_LOGOUT +import np.com.naxa.staffattendance.data.TokenMananger +import np.com.naxa.staffattendance.database.DatabaseHelper +import np.com.naxa.staffattendance.login.LoginActivity +import np.com.naxa.staffattendance.utlils.DialogFactory +import java.util.* + + +class SettingsFragment : PreferenceFragment(), Preference.OnPreferenceClickListener { + + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + init() + initNavigationPrefs() + } + + private fun initNavigationPrefs() { + + + } + + private fun init() { + addPreferencesFromResource(R.xml.staff_attendance_preferences) + val formattedAppName = getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME + findPreference(KEY_APP_UPDATE).title = formattedAppName + + findPreference(KEY_APP_UPDATE).onPreferenceClickListener = this + findPreference(KEY_LOGOUT).onPreferenceClickListener = this + } + + + override fun onPreferenceClick(preference: Preference): Boolean { + when (preference.key) { + KEY_APP_UPDATE -> { + try { + val intent = Intent(Intent.ACTION_VIEW) + intent.data = Uri.parse("market://details?id" + BuildConfig.APPLICATION_ID) + startActivity(intent) + } catch (anfe: android.content.ActivityNotFoundException) { + startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=${BuildConfig.APPLICATION_ID}"))) + } + } + KEY_LOGOUT -> logoutConfirmDialog() + } + return false + } + + private fun logoutConfirmDialog() { + val a = DatabaseHelper.getDatabaseHelper().getNewStaffCount(DatabaseHelper.getDatabaseHelper().writableDatabase) + val b = DatabaseHelper.getDatabaseHelper().getFinalizedCount(DatabaseHelper.getDatabaseHelper().writableDatabase) + + if (a + b > 0) run { + var msg = "If you logout all your account data including" + if (a > 0) msg += String.format(Locale.US, "%d un-synced staff(s)", a) + if (b > 0) msg += String.format(Locale.US, "\n %d finalized attendance(s)", b) + msg += "\nwill be deleted." + val btnText = "Delete and logout"; + + DialogFactory.createActionDialog(activity, "Caution", msg) + .setPositiveButton(btnText) { dialogInterface, i -> + dialogInterface.dismiss() + clearCache() + } + .setNegativeButton("Dismiss") { dialogInterface, i -> dialogInterface.dismiss() } + .create() + .show() + } else { + clearCache() + } + + + } + + fun clearCache() { + + TokenMananger.clearToken() + SharedPreferenceUtils.purge(activity) + DatabaseHelper.getDatabaseHelper().delteAllRows(DatabaseHelper.getDatabaseHelper().writableDatabase) + LoginActivity.start(activity) + activity.finish() + } + +} \ No newline at end of file diff --git a/app/src/main/java/np/com/naxa/staffattendance/settings/SettingsActivity.kt b/app/src/main/java/np/com/naxa/staffattendance/settings/SettingsActivity.kt new file mode 100644 index 0000000..3b5bf9a --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/settings/SettingsActivity.kt @@ -0,0 +1,46 @@ +package np.com.naxa.staffattendance.settings + +import android.content.Context +import android.content.Intent +import android.support.v7.app.AppCompatActivity +import android.os.Bundle +import android.view.MenuItem +import kotlinx.android.synthetic.main.activity_dashboard_attedance.* +import np.com.naxa.staffattendance.R +import np.com.naxa.staffattendance.attedancedashboard.AttendancesDashboardActivity + +class SettingsActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_settings) + + setupToolbar(title = getString(R.string.title_activity_settings)) + } + + + override fun onOptionsItemSelected(item: MenuItem?): Boolean { + when (item?.itemId) { + android.R.id.home -> onBackPressed(); + } + return super.onOptionsItemSelected(item) + } + + private fun setupToolbar(title: String) { + setSupportActionBar(toolbar) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + supportActionBar?.setDisplayShowTitleEnabled(false) + supportActionBar?.title = "" + supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_toolbar_back) + tv_screen_name.text = title + + } + + + companion object { + fun newIntent(context: Context): Intent { + val intent = Intent(context, SettingsActivity::class.java) + return intent + } + } +} diff --git a/app/src/main/java/np/com/naxa/staffattendance/splash/SplashScreenActivity.kt b/app/src/main/java/np/com/naxa/staffattendance/splash/SplashScreenActivity.kt new file mode 100644 index 0000000..20f695e --- /dev/null +++ b/app/src/main/java/np/com/naxa/staffattendance/splash/SplashScreenActivity.kt @@ -0,0 +1,79 @@ +package np.com.naxa.staffattendance.splash + +import android.animation.Animator +import android.animation.AnimatorListenerAdapter +import android.os.Build +import android.os.Bundle +import android.os.Handler +import android.support.v7.app.AppCompatActivity +import android.transition.Fade +import android.view.View +import android.view.Window +import android.view.WindowManager +import kotlinx.android.synthetic.main.activity_splash_screen2.* +import np.com.naxa.staffattendance.attedancedashboard.AttendancesDashboardActivity +import np.com.naxa.staffattendance.data.TokenMananger +import np.com.naxa.staffattendance.login.LoginActivity + + +class SplashScreenActivity : AppCompatActivity() { + + + private var hanlder = Handler(); + private var runnable = Runnable { + startActivity(AttendancesDashboardActivity.newIntent(this)) + + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + makeActivityFullScreen() + with(window) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + requestFeature(Window.FEATURE_CONTENT_TRANSITIONS) + exitTransition = Fade() + } + } + + setContentView(np.com.naxa.staffattendance.R.layout.activity_splash_screen2) + crossfade(); + + } + + private fun crossfade() { + + + splash_logo.alpha = 1f + splash_logo.visibility = View.VISIBLE + splash_logo.animate() + .alpha(0f) + .setStartDelay(1000L) + .setDuration(500L) + .setListener(object : AnimatorListenerAdapter() { + override fun onAnimationEnd(animation: Animator) { + + if (TokenMananger.doesTokenExist()) { + startActivity(AttendancesDashboardActivity.newIntent(this@SplashScreenActivity)) + }else{ + LoginActivity.start(this@SplashScreenActivity) + } + overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out) + finish() + + } + }) + } + + + override fun onPause() { + super.onPause() + hanlder.removeCallbacks(runnable); + } + + private fun makeActivityFullScreen() { + requestWindowFeature(Window.FEATURE_NO_TITLE) + window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN) + } + +} diff --git a/app/src/main/java/np/com/naxa/staffattendance/utlils/DateConvertor.java b/app/src/main/java/np/com/naxa/staffattendance/utlils/DateConvertor.java index 76eef2d..8130ab6 100644 --- a/app/src/main/java/np/com/naxa/staffattendance/utlils/DateConvertor.java +++ b/app/src/main/java/np/com/naxa/staffattendance/utlils/DateConvertor.java @@ -1,19 +1,42 @@ package np.com.naxa.staffattendance.utlils; +import android.annotation.SuppressLint; + import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; +import java.util.HashMap; import java.util.Locale; +import java.util.TimeZone; public class DateConvertor { + @SuppressLint("UseSparseArrays") + private static HashMap month = new HashMap<>(); + public static String getCurrentDate() { Date cDate = new Date(); return formatDate(cDate); } + + static { + month.put(0, "January"); + month.put(1, "February"); + month.put(2, "March"); + month.put(3, "April"); + month.put(4, "May"); + month.put(5, "June"); + month.put(6, "July"); + month.put(7, "August"); + month.put(8, "September"); + month.put(9, "October"); + month.put(10, "November"); + month.put(11, "December"); + } + public static String formatDate(Date date) { return new SimpleDateFormat("yyyy-MM-dd", Locale.US).format(date); } @@ -48,4 +71,82 @@ public static Date getPastDate(int days) { Date pastDate = cal.getTime(); return pastDate; } + + public static String[] getYearMonthDay(Date date) { + + Calendar cal = Calendar.getInstance(TimeZone.getDefault()); + cal.setTime(date); + int year = cal.get(Calendar.YEAR); + int month = cal.get(Calendar.MONTH); + int day = cal.get(Calendar.DAY_OF_MONTH); + + return new String[]{ + getDayOfMonth(month) + ", " + year, String.valueOf(day), getDayOfWeek(cal.get(Calendar.DAY_OF_WEEK)) + }; + } + + + private static String getDayOfMonth(int value) { + return month.get(value); + } + + private static String getDayOfWeek(int value) { + String day = ""; + switch (value) { + case 1: + day = "Sunday"; + break; + case 2: + day = "Monday"; + break; + case 3: + day = "Tuesday"; + break; + case 4: + day = "Wednesday"; + break; + case 5: + day = "Thursday"; + break; + case 6: + day = "Friday"; + break; + case 7: + day = "Saturday"; + break; + } + return day; + } + + + public static Date getDateForPosition(int pos) { + Date date; + + switch (pos) { + case 0: + date = DateConvertor.getPastDate(-6); + break; + case 1: + date = DateConvertor.getPastDate(-5); + break; + case 2: + date = DateConvertor.getPastDate(-4); + break; + case 3: + date = DateConvertor.getPastDate(-3); + break; + case 4: + date = DateConvertor.getPastDate(-2); + break; + case 5: + date = DateConvertor.getPastDate(-1); + break; + default: + date = new Date(); + break; + } + + + return date; + } } diff --git a/app/src/main/res/drawable/bg_progress.xml b/app/src/main/res/drawable/bg_progress.xml new file mode 100644 index 0000000..b02e6fe --- /dev/null +++ b/app/src/main/res/drawable/bg_progress.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/border.xml b/app/src/main/res/drawable/border.xml new file mode 100644 index 0000000..a347198 --- /dev/null +++ b/app/src/main/res/drawable/border.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_add_24dp.xml b/app/src/main/res/drawable/ic_add_24dp.xml new file mode 100644 index 0000000..d669972 --- /dev/null +++ b/app/src/main/res/drawable/ic_add_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_arrow_24dp.xml b/app/src/main/res/drawable/ic_arrow_24dp.xml new file mode 100644 index 0000000..6400429 --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_settings_24dp.xml b/app/src/main/res/drawable/ic_settings_24dp.xml new file mode 100644 index 0000000..1397d37 --- /dev/null +++ b/app/src/main/res/drawable/ic_settings_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_toolbar_back.xml b/app/src/main/res/drawable/ic_toolbar_back.xml new file mode 100644 index 0000000..b79d00f --- /dev/null +++ b/app/src/main/res/drawable/ic_toolbar_back.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/logo.png b/app/src/main/res/drawable/logo.png new file mode 100644 index 0000000..c8f8021 Binary files /dev/null and b/app/src/main/res/drawable/logo.png differ diff --git a/app/src/main/res/drawable/toolbar_gradient.xml b/app/src/main/res/drawable/toolbar_gradient.xml index 7ae76f6..cc24ab9 100644 --- a/app/src/main/res/drawable/toolbar_gradient.xml +++ b/app/src/main/res/drawable/toolbar_gradient.xml @@ -2,7 +2,7 @@ android:shape="rectangle"> diff --git a/app/src/main/res/layout/activity_attedance.xml b/app/src/main/res/layout/activity_attedance.xml new file mode 100644 index 0000000..d8fb324 --- /dev/null +++ b/app/src/main/res/layout/activity_attedance.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_dashboard_attedance.xml b/app/src/main/res/layout/activity_dashboard_attedance.xml new file mode 100644 index 0000000..ddce794 --- /dev/null +++ b/app/src/main/res/layout/activity_dashboard_attedance.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_login_page.xml b/app/src/main/res/layout/activity_login_page.xml index 26f6a39..320697f 100644 --- a/app/src/main/res/layout/activity_login_page.xml +++ b/app/src/main/res/layout/activity_login_page.xml @@ -1,9 +1,10 @@ + + android:layout_height="match_parent"> + android:layout_marginTop="230dp" + android:layout_marginBottom="8dp"> + app:passwordToggleEnabled="true"> - diff --git a/app/src/main/res/layout/activity_new_staff.xml b/app/src/main/res/layout/activity_new_staff.xml index 7647111..f149039 100644 --- a/app/src/main/res/layout/activity_new_staff.xml +++ b/app/src/main/res/layout/activity_new_staff.xml @@ -1,23 +1,45 @@ - + android:layout_height="match_parent"> - + + + + + + + - + + + + + app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"> - + - - + + diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml new file mode 100644 index 0000000..8b59782 --- /dev/null +++ b/app/src/main/res/layout/activity_settings.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_splash_screen2.xml b/app/src/main/res/layout/activity_splash_screen2.xml new file mode 100644 index 0000000..d01fab0 --- /dev/null +++ b/app/src/main/res/layout/activity_splash_screen2.xml @@ -0,0 +1,31 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/flexible_toolbar.xml b/app/src/main/res/layout/flexible_toolbar.xml index 3800dc5..2233d50 100644 --- a/app/src/main/res/layout/flexible_toolbar.xml +++ b/app/src/main/res/layout/flexible_toolbar.xml @@ -9,7 +9,7 @@ + /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_take_attedance_dialog.xml b/app/src/main/res/layout/fragment_take_attedance_dialog.xml new file mode 100644 index 0000000..c5e78ef --- /dev/null +++ b/app/src/main/res/layout/fragment_take_attedance_dialog.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/grid_item_add.xml b/app/src/main/res/layout/grid_item_add.xml new file mode 100644 index 0000000..d0a94e8 --- /dev/null +++ b/app/src/main/res/layout/grid_item_add.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/grid_item_calendra.xml b/app/src/main/res/layout/grid_item_calendra.xml new file mode 100644 index 0000000..033b588 --- /dev/null +++ b/app/src/main/res/layout/grid_item_calendra.xml @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/grid_item_stats.xml b/app/src/main/res/layout/grid_item_stats.xml new file mode 100644 index 0000000..4d5f404 --- /dev/null +++ b/app/src/main/res/layout/grid_item_stats.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/header.xml b/app/src/main/res/layout/header.xml new file mode 100644 index 0000000..c08bfd1 --- /dev/null +++ b/app/src/main/res/layout/header.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/staff_data_edit_form.xml b/app/src/main/res/layout/staff_data_edit_form.xml index 92e510d..bd951b5 100644 --- a/app/src/main/res/layout/staff_data_edit_form.xml +++ b/app/src/main/res/layout/staff_data_edit_form.xml @@ -421,11 +421,21 @@ android:text="Save" android:visibility="gone" /> -