diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/pathtracking/PathTrackingActivity.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/pathtracking/PathTrackingActivity.java index 35b593f2075..01ef4021563 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/pathtracking/PathTrackingActivity.java +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/pathtracking/PathTrackingActivity.java @@ -15,11 +15,6 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -30,7 +25,6 @@ import com.mifos.mifosxdroid.R; import com.mifos.mifosxdroid.adapters.PathTrackingAdapter; import com.mifos.mifosxdroid.core.MifosBaseActivity; -import com.mifos.mifosxdroid.core.RecyclerItemClickListener; import com.mifos.objects.user.UserLatLng; import com.mifos.objects.user.UserLocation; import com.mifos.utils.CheckSelfPermissionAndRequest; @@ -42,6 +36,11 @@ import javax.inject.Inject; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; @@ -49,8 +48,7 @@ /** * @author fomenkoo */ -public class PathTrackingActivity extends MifosBaseActivity implements PathTrackingMvpView, - SwipeRefreshLayout.OnRefreshListener, RecyclerItemClickListener.OnItemClickListener { +public class PathTrackingActivity extends MifosBaseActivity implements PathTrackingMvpView, SwipeRefreshLayout.OnRefreshListener { @BindView(R.id.rv_path_tacker) RecyclerView rvPathTracker; @@ -67,7 +65,6 @@ public class PathTrackingActivity extends MifosBaseActivity implements PathTrack @Inject PathTrackingPresenter pathTrackingPresenter; - @Inject PathTrackingAdapter pathTrackingAdapter; private Intent intentLocationService; @@ -75,24 +72,6 @@ public class PathTrackingActivity extends MifosBaseActivity implements PathTrack private List userLocations; private SweetUIErrorHandler sweetUIErrorHandler; - @Override - public void onItemClick(View childView, int position) { - List userLatLngs = - pathTrackingAdapter.getLatLngList(userLocations.get(position).getLatlng()); - String uri = "http://maps.google.com/maps?f=d&hl=en&saddr=" - + userLatLngs.get(0).getLat() + "," + userLatLngs.get(0).getLng() + "&daddr=" - + userLatLngs.get(userLatLngs.size() - 1).getLat() + "," + "" - + userLatLngs.get(userLatLngs.size() - 1).getLng(); - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); - intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); - startActivity(Intent.createChooser(intent, getString(R.string.start_tracking))); - } - - @Override - public void onItemLongPress(View childView, int position) { - - } - @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -113,14 +92,24 @@ public void showUserInterface() { userLocations = new ArrayList<>(); LinearLayoutManager mLayoutManager = new LinearLayoutManager(this); mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); - pathTrackingAdapter.setContext(this); mLayoutManager.setReverseLayout(true); mLayoutManager.setStackFromEnd(true); rvPathTracker.setLayoutManager(mLayoutManager); rvPathTracker.setHasFixedSize(false); rvPathTracker.scrollToPosition(0); + pathTrackingAdapter = new PathTrackingAdapter(userLocation -> { + List userLatLngs = + pathTrackingAdapter.getLatLngList(userLocation.getLatlng()); + String uri = "http://maps.google.com/maps?f=d&hl=en&saddr=" + + userLatLngs.get(0).getLat() + "," + userLatLngs.get(0).getLng() + "&daddr=" + + userLatLngs.get(userLatLngs.size() - 1).getLat() + "," + "" + + userLatLngs.get(userLatLngs.size() - 1).getLng(); + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); + intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); + startActivity(Intent.createChooser(intent, getString(R.string.start_tracking))); + return null; + }); rvPathTracker.setAdapter(pathTrackingAdapter); - rvPathTracker.addOnItemTouchListener(new RecyclerItemClickListener(this, this)); swipeRefreshLayout.setColorSchemeColors(this .getResources().getIntArray(R.array.swipeRefreshColors)); swipeRefreshLayout.setOnRefreshListener(this); @@ -200,6 +189,7 @@ public void requestPermission() { public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case Constants.PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION: { // If request is cancelled, the result arrays are empty. @@ -210,7 +200,7 @@ public void onRequestPermissionsResult(int requestCode, } else { // permission denied Toast.makeText(getApplicationContext(), getResources() - .getString(R.string.permission_denied_to_access_fine_location) , + .getString(R.string.permission_denied_to_access_fine_location), Toast.LENGTH_SHORT).show(); } } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/CentersListAdapter.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/CentersListAdapter.java deleted file mode 100755 index e48db80f84f..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/CentersListAdapter.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ - -package com.mifos.mifosxdroid.adapters; - -import android.content.Context; -import android.graphics.Color; -import androidx.core.content.ContextCompat; -import androidx.recyclerview.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.mifos.mifosxdroid.R; -import com.mifos.mifosxdroid.core.SelectableAdapter; -import com.mifos.mifosxdroid.views.CircularImageView; -import com.mifos.objects.group.Center; -import com.mifos.utils.Utils; - -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Inject; - -import butterknife.BindView; -import butterknife.ButterKnife; - -/** - * Created by ishankhanna on 11/03/14. - */ -public class CentersListAdapter extends SelectableAdapter { - - private List
centers; - private Context context; - - @Inject - public CentersListAdapter() { - centers = new ArrayList<>(); - } - - @Override - public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.row_center_list_item, parent, false); - return new CentersListAdapter.ViewHolder(view); - } - - @Override - public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) { - if (holder instanceof ViewHolder) { - Center center = centers.get(position); - - ((ViewHolder) holder).tvAccountNumber.setText(String.format(context. - getString(R.string.centerList_account_prefix), center.getAccountNo())); - ((ViewHolder) holder).tvCenterId.setText(String.valueOf(center.getId())); - ((ViewHolder) holder).tvCenterName.setText(center.getName()); - if (center.getStaffId() != null) { - ((ViewHolder) holder).tvStaffId.setText(String.valueOf(center.getStaffId())); - ((ViewHolder) holder).tvStaffName.setText(center.getStaffName()); - } else { - ((ViewHolder) holder).tvStaffId.setText(""); - ((ViewHolder) holder).tvStaffName.setText(R.string.no_staff); - } - ((ViewHolder) holder).tvOfficeId.setText(String.valueOf(center.getOfficeId())); - ((ViewHolder) holder).tvOfficeName.setText(center.getOfficeName()); - if (center.getActive()) { - ((ViewHolder) holder).ivStatusIndicator.setImageDrawable( - Utils.setCircularBackground(R.color.light_green, context)); - } else { - ((ViewHolder) holder).ivStatusIndicator.setImageDrawable( - Utils.setCircularBackground(R.color.light_red, context)); - } - - //Changing the Color of Selected Centers - ((ViewHolder) holder).viewSelectedOverlay - .setBackgroundColor(isSelected(position) ? ContextCompat.getColor(context, - R.color.gray_light) : Color.WHITE); - - ((ViewHolder) holder).ivSyncStatus - .setVisibility(center.isSync() ? View.VISIBLE : View.INVISIBLE); - } - } - - public void setContext(Context context) { - this.context = context; - } - - public void setCenters(List
centers) { - this.centers = centers; - notifyDataSetChanged(); - } - - public Center getItem(int position) { - return this.centers.get(position); - } - - @Override - public long getItemId(int i) { - return 0; - } - - @Override - public int getItemCount() { - return centers.size(); - } - - - public static class ViewHolder extends RecyclerView.ViewHolder { - - @BindView(R.id.iv_status_indicator) - CircularImageView ivStatusIndicator; - - @BindView(R.id.tv_account_number) - TextView tvAccountNumber; - - @BindView(R.id.tv_center_name) - TextView tvCenterName; - - @BindView(R.id.tv_center_id) - TextView tvCenterId; - - @BindView(R.id.tv_staff_name) - TextView tvStaffName; - - @BindView(R.id.tv_staff_id) - TextView tvStaffId; - - @BindView(R.id.tv_office_name) - TextView tvOfficeName; - - @BindView(R.id.tv_office_id) - TextView tvOfficeId; - - @BindView(R.id.linearLayout) - LinearLayout viewSelectedOverlay; - - @BindView(R.id.iv_sync_status) - ImageView ivSyncStatus; - - public ViewHolder(View v) { - super(v); - ButterKnife.bind(this, v); - } - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/CentersListAdapter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/CentersListAdapter.kt new file mode 100644 index 00000000000..4bfbdca7bfb --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/CentersListAdapter.kt @@ -0,0 +1,104 @@ +package com.mifos.mifosxdroid.adapters + +import android.graphics.Color +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.RecyclerView +import com.mifos.mifosxdroid.R +import com.mifos.mifosxdroid.core.SelectableAdapter +import com.mifos.mifosxdroid.views.CircularImageView +import com.mifos.objects.group.Center +import com.mifos.utils.Utils + + +class CentersListAdapter( + val onCenterClick: (Int) -> Unit, + val onCenterLongClick: (Int) -> Unit +) : SelectableAdapter() { + + private var centers: List
= ArrayList() + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val viewHolder = ViewHolder( + LayoutInflater.from(parent.context) + .inflate(R.layout.row_center_list_item, parent, false) + ) + viewHolder.itemView.setOnClickListener { + if(viewHolder.adapterPosition != RecyclerView.NO_POSITION) + onCenterClick(viewHolder.adapterPosition) + } + viewHolder.itemView.setOnLongClickListener { + if(viewHolder.adapterPosition != RecyclerView.NO_POSITION) + onCenterLongClick(viewHolder.adapterPosition) + return@setOnLongClickListener true + } + return viewHolder + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val center = centers[position] + holder.apply { + tvAccountNumber.text = String.format( + itemView.context.getString(R.string.centerList_account_prefix), center.accountNo + ) + tvCenterId.text = center.id.toString() + tvCenterName.text = center.name + if (center.staffId != null) { + tvStaffId.text = center.staffId.toString() + tvStaffName.text = center.staffName + } else { + tvStaffId.text = "" + tvStaffName.setText(R.string.no_staff) + } + tvOfficeId.text = center.officeId.toString() + tvOfficeName.text = center.officeName + ivStatusIndicator.setImageDrawable( + Utils.setCircularBackground( + if(center.active) R.color.light_green else R.color.light_red, + itemView.context + ) + ) + + //Changing the Color of Selected Centers + viewSelectedOverlay.setBackgroundColor( + if (isSelected(position)) + ContextCompat.getColor(itemView.context,R.color.gray_light) + else Color.WHITE + ) + ivSyncStatus.visibility = if (center.isSync) View.VISIBLE else View.INVISIBLE + } + } + + + fun setCenters(centers: List
) { + this.centers = centers + notifyDataSetChanged() + } + + fun getItem(position: Int) = centers[position] + + + override fun getItemId(i: Int) = 0L + + override fun getItemCount() = centers.size + + + class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { + val ivStatusIndicator: CircularImageView = v.findViewById(R.id.iv_status_indicator) + val tvAccountNumber: TextView = v.findViewById(R.id.tv_account_number) + val tvCenterName: TextView = v.findViewById(R.id.tv_center_name) + val tvCenterId: TextView = v.findViewById(R.id.tv_center_id) + val tvStaffName: TextView = v.findViewById(R.id.tv_staff_name) + val tvStaffId: TextView = v.findViewById(R.id.tv_staff_id) + val tvOfficeName: TextView = v.findViewById(R.id.tv_office_name) + val tvOfficeId: TextView = v.findViewById(R.id.tv_office_id) + val viewSelectedOverlay: LinearLayout = v.findViewById(R.id.linearLayout) + val ivSyncStatus: ImageView = v.findViewById(R.id.iv_sync_status) + } + +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ChargeNameListAdapter.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ChargeNameListAdapter.java deleted file mode 100755 index 88e3bb8c7c2..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ChargeNameListAdapter.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ - -package com.mifos.mifosxdroid.adapters; - -import android.content.Context; -import androidx.recyclerview.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import com.mifos.mifosxdroid.R; -import com.mifos.objects.client.Charges; - -import java.util.List; - -import butterknife.BindView; -import butterknife.ButterKnife; - -/** - * Created by ishankhanna on 03/07/14. - */ -public class ChargeNameListAdapter extends RecyclerView.Adapter { - - Context context; - LayoutInflater layoutInflater; - List pageItems; - int clientId; - - public ChargeNameListAdapter(Context context, List pageItems, int clientId) { - this.context = context; - layoutInflater = LayoutInflater.from(context); - this.pageItems = pageItems; - this.clientId = clientId; - } - - public Charges getItem(int position) { - return pageItems.get(position); - } - - @Override - public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - RecyclerView.ViewHolder vh; - View v = LayoutInflater.from(parent.getContext()).inflate( - R.layout.row_charge_name, parent, false); - vh = new ViewHolder(v); - return vh; - } - - @Override - public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { - if (holder instanceof ViewHolder) { - ((ViewHolder) holder).tv_charger_id - .setText(pageItems.get(position).getChargeId().toString()); - ((ViewHolder) holder).tv_charge_Name.setText(pageItems.get(position).getName()); - ((ViewHolder) holder).tv_charge_amount - .setText(pageItems.get(position).getAmount().toString()); - ((ViewHolder) holder).tv_charge_duedate - .setText(pageItems.get(position).getFormattedDueDate()); - } - } - - @Override - public long getItemId(int i) { - return 0; - } - - @Override - public int getItemCount() { - return pageItems.size(); - } - - - public static class ViewHolder extends RecyclerView.ViewHolder { - - @BindView(R.id.tv_charger_id) - TextView tv_charger_id; - - @BindView(R.id.tv_chargeName) - TextView tv_charge_Name; - - @BindView(R.id.tv_charge_amount) - TextView tv_charge_amount; - - @BindView(R.id.tv_charge_duedate) - TextView tv_charge_duedate; - - public ViewHolder(View v) { - super(v); - ButterKnife.bind(this, v); - } - } - -} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ChargeNameListAdapter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ChargeNameListAdapter.kt new file mode 100644 index 00000000000..926465d0df3 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ChargeNameListAdapter.kt @@ -0,0 +1,46 @@ +package com.mifos.mifosxdroid.adapters + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.mifos.mifosxdroid.R +import com.mifos.objects.client.Charges + + +class ChargeNameListAdapter( + var pageItems: List, + var clientId: Int +) : RecyclerView.Adapter() { + + fun getItem(position: Int) = pageItems[position] + + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val viewHolder = ViewHolder( + LayoutInflater.from(parent.context) + .inflate(R.layout.row_charge_name, parent, false) + ) + return viewHolder + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + holder.tv_charger_id.text = pageItems[position].chargeId.toString() + holder.tv_charge_Name.text = pageItems[position].name + holder.tv_charge_amount.text = pageItems[position].amount.toString() + holder.tv_charge_duedate.text = pageItems[position].formattedDueDate + } + + override fun getItemId(i: Int) = 0L + + override fun getItemCount() = pageItems.size + + + class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { + val tv_charger_id: TextView = v.findViewById(R.id.tv_charger_id) + val tv_charge_Name: TextView = v.findViewById(R.id.tv_chargeName) + val tv_charge_amount: TextView = v.findViewById(R.id.tv_charge_amount) + val tv_charge_duedate: TextView = v.findViewById(R.id.tv_charge_duedate) + } +} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ClientNameListAdapter.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ClientNameListAdapter.java deleted file mode 100755 index a5cfde0ad65..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ClientNameListAdapter.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ - -package com.mifos.mifosxdroid.adapters; - -import android.content.Context; -import android.graphics.Color; -import androidx.core.content.ContextCompat; -import androidx.recyclerview.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.mifos.mifosxdroid.R; -import com.mifos.mifosxdroid.core.SelectableAdapter; -import com.mifos.objects.client.Client; -import com.mifos.utils.ImageLoaderUtils; - -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Inject; - -import butterknife.BindView; -import butterknife.ButterKnife; - -/** - * Created by ishankhanna on 27/02/14. - */ -public class ClientNameListAdapter extends SelectableAdapter { - - private List pageItems; - private Context mContext; - - @Inject - public ClientNameListAdapter() { - this.pageItems = new ArrayList<>(); - } - - public Client getItem(int position) { - return pageItems.get(position); - } - - @Override - public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - RecyclerView.ViewHolder vh; - View v = LayoutInflater.from(parent.getContext()).inflate( - R.layout.row_client_name, parent, false); - vh = new ViewHolder(v); - return vh; - } - - @Override - public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) { - if (holder instanceof ViewHolder) { - - Client client = getItem(position); - String clientName; - if (client.getFullname() == null) { - clientName = client.getFirstname() + " " + client.getLastname(); - } else { - clientName = client.getFullname(); - } - ((ViewHolder) holder).tv_clientName.setText(clientName); - ((ViewHolder) holder).tv_clientAccountNumber.setText(client.getAccountNo()); - - // lazy the load profile picture - if (client.isImagePresent()) { - // make the image url - ImageLoaderUtils.loadImage(mContext, client.getId(), - ((ViewHolder) holder).iv_userPicture); - } else { - ((ViewHolder) holder).iv_userPicture.setImageResource(R.drawable.ic_dp_placeholder); - } - - //Changing the Color of Selected Clients - ((ViewHolder) holder).view_selectedOverlay - .setBackgroundColor(isSelected(position) ? ContextCompat.getColor(mContext, - R.color.gray_light) : Color.WHITE); - - ((ViewHolder) holder).iv_sync_status - .setVisibility(client.isSync() ? View.VISIBLE : View.INVISIBLE); - } - } - - @Override - public long getItemId(int i) { - return 0; - } - - @Override - public int getItemCount() { - return pageItems.size(); - } - - public void setContext(Context context) { - mContext = context; - } - - public void setClients(List clients) { - pageItems = clients; - } - - public void updateItem(int position) { - notifyItemChanged(position); - } - - public static class ViewHolder extends RecyclerView.ViewHolder { - - @BindView(R.id.tv_clientName) - TextView tv_clientName; - - @BindView(R.id.tv_clientAccountNumber) - TextView tv_clientAccountNumber; - - @BindView(R.id.iv_user_picture) - ImageView iv_userPicture; - - @BindView(R.id.linearLayout) - LinearLayout view_selectedOverlay; - - @BindView(R.id.iv_sync_status) - ImageView iv_sync_status; - - public ViewHolder(View v) { - super(v); - ButterKnife.bind(this, v); - } - } -} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ClientNameListAdapter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ClientNameListAdapter.kt new file mode 100644 index 00000000000..82d5e12405f --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ClientNameListAdapter.kt @@ -0,0 +1,89 @@ +package com.mifos.mifosxdroid.adapters + +import android.graphics.Color +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.RecyclerView +import com.mifos.mifosxdroid.R +import com.mifos.mifosxdroid.core.SelectableAdapter +import com.mifos.objects.client.Client +import com.mifos.utils.ImageLoaderUtils + + +class ClientNameListAdapter( + val onClientNameClick: (Int) -> Unit, + val onClientNameLongClick: (Int) -> Unit +) : SelectableAdapter() { + private var pageItems: List = ArrayList() + + fun getItem(position: Int) = pageItems[position] + + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val viewHolder = ViewHolder( + LayoutInflater.from(parent.context) + .inflate(R.layout.row_client_name, parent, false) + ) + viewHolder.itemView.setOnClickListener { + if(viewHolder.adapterPosition != RecyclerView.NO_POSITION) + onClientNameClick(viewHolder.adapterPosition) + } + viewHolder.itemView.setOnLongClickListener { + if(viewHolder.adapterPosition != RecyclerView.NO_POSITION) + onClientNameLongClick(viewHolder.adapterPosition) + return@setOnLongClickListener true + } + return viewHolder + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val client = getItem(position) + val clientName = client.fullname ?: (client.firstname + " " + client.lastname) + + holder.tv_clientName.text = clientName + holder.tv_clientAccountNumber.text = client.accountNo + + // lazy the load profile picture + if (client.isImagePresent) { + // make the image url + ImageLoaderUtils.loadImage(holder.itemView.context, client.id, holder.iv_userPicture) + } else { + holder.iv_userPicture.setImageResource(R.drawable.ic_dp_placeholder) + } + + //Changing the Color of Selected Clients + holder.view_selectedOverlay.setBackgroundColor( + if (isSelected(position)) + ContextCompat.getColor(holder.itemView.context, R.color.gray_light) + else + Color.WHITE + ) + holder.iv_sync_status.visibility = if (client.isSync) View.VISIBLE else View.INVISIBLE + } + + override fun getItemId(i: Int) = 0L + + override fun getItemCount() = pageItems.size + + fun setClients(clients: List) { + pageItems = clients + } + + fun updateItem(position: Int) { + notifyItemChanged(position) + } + + class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { + val tv_clientName: TextView = v.findViewById(R.id.tv_clientName) + val tv_clientAccountNumber: TextView = v.findViewById(R.id.tv_clientAccountNumber) + val iv_userPicture: ImageView = v.findViewById(R.id.iv_user_picture) + val view_selectedOverlay: LinearLayout = v.findViewById(R.id.linearLayout) + val iv_sync_status: ImageView = v.findViewById(R.id.iv_sync_status) + + } +} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ClientReportAdapter.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ClientReportAdapter.java deleted file mode 100644 index 9c66c344590..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ClientReportAdapter.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.mifos.mifosxdroid.adapters; - -import androidx.recyclerview.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import com.mifos.mifosxdroid.R; -import com.mifos.objects.runreports.client.ClientReportTypeItem; - -import java.util.List; - -import javax.inject.Inject; - -import butterknife.BindView; -import butterknife.ButterKnife; - -/** - * Created by Tarun on 03-08-17. - */ - -public class ClientReportAdapter extends - RecyclerView.Adapter { - - private List items; - - @Inject - public ClientReportAdapter() {} - - public void setReportItems(List items) { - this.items = items; - } - - @Override - public ClientReportAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_client_runreport, parent, false); - - return new ClientReportAdapter.ViewHolder(view); - } - - @Override - public void onBindViewHolder(ClientReportAdapter.ViewHolder holder, int position) { - if (holder != null) { - holder.tvReportCategory.setText(items.get(position).getReportCategory()); - holder.tvReportName.setText(items.get(position).getReportName()); - holder.tvReportType.setText(items.get(position).getReportType()); - } - } - - @Override - public int getItemCount() { - return items.size(); - } - - public class ViewHolder extends RecyclerView.ViewHolder { - - public ViewHolder(View v) { - super(v); - ButterKnife.bind(this, v); - } - - @BindView(R.id.tv_report_name) - TextView tvReportName; - - @BindView(R.id.tv_report_type) - TextView tvReportType; - - @BindView(R.id.tv_report_category) - TextView tvReportCategory; - } - -} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ClientReportAdapter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ClientReportAdapter.kt new file mode 100644 index 00000000000..2c5a483df2d --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ClientReportAdapter.kt @@ -0,0 +1,48 @@ +package com.mifos.mifosxdroid.adapters + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.mifos.mifosxdroid.R +import com.mifos.objects.runreports.client.ClientReportTypeItem + + +class ClientReportAdapter( + val onClientReportClick: (Int) -> Unit +) : RecyclerView.Adapter() { + private var items: List = emptyList() + + + fun setReportItems(items: List) { + this.items = items + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val viewHolder = ViewHolder( + LayoutInflater.from(parent.context) + .inflate(R.layout.item_client_runreport, parent, false) + ) + viewHolder.itemView.setOnClickListener { + if(viewHolder.adapterPosition != RecyclerView.NO_POSITION) + onClientReportClick(viewHolder.adapterPosition) + } + return viewHolder + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + holder.tvReportCategory.text = items[position].reportCategory + holder.tvReportName.text = items[position].reportName + holder.tvReportType.text = items[position].reportType + } + + override fun getItemCount() = items.size + + + class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { + val tvReportName: TextView = v.findViewById(R.id.tv_report_name) + val tvReportType: TextView = v.findViewById(R.id.tv_report_type) + val tvReportCategory: TextView = v.findViewById(R.id.tv_report_category) + } +} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/DataTableAdapter.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/DataTableAdapter.java deleted file mode 100644 index 1ee880cff9d..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/DataTableAdapter.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.mifos.mifosxdroid.adapters; - -import androidx.recyclerview.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import com.mifos.mifosxdroid.R; -import com.mifos.objects.noncore.DataTable; - -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Inject; - -import butterknife.BindView; -import butterknife.ButterKnife; - -/** - * Created by Rajan Maurya on 12/02/17. - */ -public class DataTableAdapter extends RecyclerView.Adapter { - - List dataTables; - - @Inject - public DataTableAdapter() { - dataTables = new ArrayList<>(); - } - - @Override - public DataTableAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_data_table, parent, false); - return new ViewHolder(view); - } - - @Override - public void onBindViewHolder(final DataTableAdapter.ViewHolder holder, int position) { - DataTable dataTable = dataTables.get(position); - holder.tvDataTableName.setText(dataTable.getRegisteredTableName()); - } - - - public void setDataTables(List dataTables) { - this.dataTables = dataTables; - notifyDataSetChanged(); - } - - @Override - public int getItemCount() { - return dataTables.size(); - } - - public DataTable getItem(int position) { - return dataTables.get(position); - } - - @Override - public long getItemId(int i) { - return 0; - } - - public static class ViewHolder extends RecyclerView.ViewHolder { - - @BindView(R.id.tv_data_table_name) - TextView tvDataTableName; - - public ViewHolder(View v) { - super(v); - ButterKnife.bind(this, v); - } - } -} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/DataTableAdapter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/DataTableAdapter.kt new file mode 100644 index 00000000000..db0c09bd1cb --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/DataTableAdapter.kt @@ -0,0 +1,51 @@ +package com.mifos.mifosxdroid.adapters + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.mifos.mifosxdroid.R +import com.mifos.objects.noncore.DataTable + +class DataTableAdapter( + val onDateTableClick: (DataTable) -> Unit +) : RecyclerView.Adapter() { + var dataTables: List = ArrayList() + set(value) { + field = value + notifyDataSetChanged() + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val viewHolder = ViewHolder( + LayoutInflater.from(parent.context) + .inflate(R.layout.item_data_table, parent, false) + ) + viewHolder.itemView.setOnClickListener { + if(viewHolder.adapterPosition != RecyclerView.NO_POSITION) + onDateTableClick(dataTables[viewHolder.adapterPosition]) + } + return viewHolder + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val dataTable = dataTables[position] + holder.tvDataTableName.text = dataTable.registeredTableName + } + + override fun getItemCount() = dataTables.size + + + fun getItem(position: Int): DataTable { + return dataTables[position] + } + + override fun getItemId(i: Int): Long { + return 0 + } + + class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { + val tvDataTableName: TextView = v.findViewById(R.id.tv_data_table_name) + } +} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/DocumentListAdapter.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/DocumentListAdapter.java deleted file mode 100755 index e82e0d80adc..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/DocumentListAdapter.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ - -package com.mifos.mifosxdroid.adapters; - -import androidx.recyclerview.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import com.joanzapata.iconify.fonts.MaterialIcons; -import com.joanzapata.iconify.widget.IconTextView; -import com.mifos.mifosxdroid.R; -import com.mifos.objects.noncore.Document; - -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Inject; - -import butterknife.BindView; -import butterknife.ButterKnife; - -/** - * Created by ishankhanna on 02/07/14. - */ -public class DocumentListAdapter extends RecyclerView.Adapter { - - List documents = new ArrayList(); - - @Inject - public DocumentListAdapter() { - documents = new ArrayList<>(); - } - - public Document getItem(int i) { - return documents.get(i); - } - - @Override - public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - RecyclerView.ViewHolder vh; - View v = LayoutInflater.from(parent.getContext()).inflate( - R.layout.row_document_list, parent, false); - vh = new ViewHolder(v); - return vh; - } - - @Override - public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { - if (holder instanceof ViewHolder) { - - ((ViewHolder) holder).tv_doc_name.setText(documents.get(position).getName()); - ((ViewHolder) holder).tv_doc_description - .setText(documents.get(position).getDescription() == null ? - "-" : documents.get(position).getDescription()); - - MaterialIcons cloudIcon = MaterialIcons.md_cloud_download; -// Iconify.IconValue cloudIcon = Iconify.IconValue.fa_download; - - //TODO Implement Local Storage Check to show File Download Info - //Iconify.IconValue storageIcon = Iconify.IconValue.fa_hdd_o; - - ((ViewHolder) holder).tv_doc_location_icon.setText("{" + cloudIcon.key() + "}"); - -// Iconify.addIcons(reusableDocumentViewHolder.tv_doc_location_icon); - } - } - - public void setDocuments(List documentList) { - documents = documentList; - notifyDataSetChanged(); - } - - @Override - public long getItemId(int i) { - return 0; - } - - @Override - public int getItemCount() { - return documents.size(); - } - - public static class ViewHolder extends RecyclerView.ViewHolder { - - @BindView(R.id.tv_doc_name) - TextView tv_doc_name; - - @BindView(R.id.tv_doc_descrption) - TextView tv_doc_description; - - @BindView(R.id.tv_doc_location_icon) - IconTextView tv_doc_location_icon; - - public ViewHolder(View v) { - super(v); - ButterKnife.bind(this, v); - } - } -} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/DocumentListAdapter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/DocumentListAdapter.kt new file mode 100644 index 00000000000..685ff21a1b7 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/DocumentListAdapter.kt @@ -0,0 +1,63 @@ +package com.mifos.mifosxdroid.adapters + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.joanzapata.iconify.fonts.MaterialIcons +import com.joanzapata.iconify.widget.IconTextView +import com.mifos.mifosxdroid.R +import com.mifos.objects.noncore.Document +import javax.inject.Inject + + +class DocumentListAdapter( + val onDocumentClick: (Document) -> Unit +) : RecyclerView.Adapter() { + var documents: List = emptyList() + set(value) { + field = value + notifyDataSetChanged() + } + + fun getItem(i: Int) = documents[i] + + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val viewHolder = ViewHolder( + LayoutInflater.from(parent.context) + .inflate(R.layout.row_document_list, parent, false) + ) + viewHolder.itemView.setOnClickListener { + if(viewHolder.adapterPosition != RecyclerView.NO_POSITION) + onDocumentClick(documents[viewHolder.adapterPosition]) + } + return viewHolder + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + holder.tv_doc_name.text = documents[position].name + holder.tv_doc_description.text = + if (documents[position].description == null) "-" + else documents[position].description + + val cloudIcon = MaterialIcons.md_cloud_download + + //TODO Implement Local Storage Check to show File Download Info + //Iconify.IconValue storageIcon = Iconify.IconValue.fa_hdd_o; + holder.tv_doc_location_icon.text = "{" + cloudIcon.key() + "}" + } + + override fun getItemId(i: Int) = 0L + + + override fun getItemCount() = documents.size + + + class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { + val tv_doc_name: TextView = v.findViewById(R.id.tv_doc_name) + val tv_doc_description: TextView = v.findViewById(R.id.tv_doc_descrption) + val tv_doc_location_icon: IconTextView = v.findViewById(R.id.tv_doc_location_icon) + } +} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/GroupNameListAdapter.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/GroupNameListAdapter.java deleted file mode 100644 index d22340129f2..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/GroupNameListAdapter.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ - -package com.mifos.mifosxdroid.adapters; - -import android.content.Context; -import android.graphics.Color; -import androidx.core.content.ContextCompat; -import androidx.recyclerview.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.mifos.mifosxdroid.R; -import com.mifos.mifosxdroid.core.SelectableAdapter; -import com.mifos.objects.group.Group; - -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Inject; - -import butterknife.BindView; -import butterknife.ButterKnife; - -public class GroupNameListAdapter extends SelectableAdapter { - - private List groups; - private Context context; - - @Inject - public GroupNameListAdapter() { - this.groups = new ArrayList<>(); - } - - @Override - public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - RecyclerView.ViewHolder vh; - View v = LayoutInflater.from(parent.getContext()).inflate( - R.layout.row_group_name, parent, false); - vh = new ViewHolder(v); - return vh; - } - - @Override - public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) { - if (holder instanceof ViewHolder) { - Group group = groups.get(position); - - ((ViewHolder) holder).tv_groupsName.setText(group.getName()); - ((ViewHolder) holder).tv_groupsId.setText(String.valueOf(group.getId())); - - //Changing the Color of Selected Groups - ((ViewHolder) holder).view_selectedOverlay - .setBackgroundColor(isSelected(position) ? ContextCompat.getColor(context, - R.color.gray_light) : Color.WHITE); - - ((ViewHolder) holder).iv_sync_status - .setVisibility(group.isSync() ? View.VISIBLE : View.INVISIBLE); - } - } - - - public void setGroups(List groups) { - this.groups = groups; - notifyDataSetChanged(); - } - - public void setContext(Context context) { - this.context = context; - } - - @Override - public int getItemCount() { - return groups.size(); - } - - public Group getItem(int position) { - return groups.get(position); - } - - @Override - public long getItemId(int i) { - return 0; - } - - public static class ViewHolder extends RecyclerView.ViewHolder { - - @BindView(R.id.tv_group_name) - TextView tv_groupsName; - - @BindView(R.id.tv_group_id) - TextView tv_groupsId; - - @BindView(R.id.linearLayout) - LinearLayout view_selectedOverlay; - - @BindView(R.id.iv_sync_status) - ImageView iv_sync_status; - - public ViewHolder(View v) { - super(v); - ButterKnife.bind(this, v); - } - } -} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/GroupNameListAdapter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/GroupNameListAdapter.kt new file mode 100644 index 00000000000..38ec71de2d4 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/GroupNameListAdapter.kt @@ -0,0 +1,74 @@ +package com.mifos.mifosxdroid.adapters + +import android.graphics.Color +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import android.widget.TextView +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.RecyclerView +import com.mifos.mifosxdroid.R +import com.mifos.mifosxdroid.core.SelectableAdapter +import com.mifos.objects.group.Group +import javax.inject.Inject + +class GroupNameListAdapter( + val onGroupClick: (Int) -> Unit, + val onGroupLongClick: (Int) -> Unit +) : SelectableAdapter() { + private var groups: List = ArrayList() + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val viewHolder = ViewHolder( + LayoutInflater.from(parent.context) + .inflate(R.layout.row_group_name, parent, false) + ) + viewHolder.itemView.setOnClickListener { + if(viewHolder.adapterPosition != RecyclerView.NO_POSITION) + onGroupClick(viewHolder.adapterPosition) + } + viewHolder.itemView.setOnLongClickListener { + if(viewHolder.adapterPosition != RecyclerView.NO_POSITION) + onGroupLongClick(viewHolder.adapterPosition) + return@setOnLongClickListener true + } + return viewHolder + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val group = groups[position] + holder.tv_groupsName.text = group.name + holder.tv_groupsId.text = group.id.toString() + + //Changing the Color of Selected Groups + holder.view_selectedOverlay.setBackgroundColor( + if (isSelected(position)) + ContextCompat.getColor(holder.itemView.context,R.color.gray_light) + else Color.WHITE + ) + holder.iv_sync_status.visibility = if (group.isSync) View.VISIBLE else View.INVISIBLE + } + + fun setGroups(groups: List) { + this.groups = groups + notifyDataSetChanged() + } + + + override fun getItemCount() = groups.size + + + fun getItem(position: Int) = groups[position] + + + override fun getItemId(i: Int) = 0L + + class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { + val tv_groupsName: TextView = v.findViewById(R.id.tv_group_name) + val tv_groupsId: TextView = v.findViewById(R.id.tv_group_id) + var view_selectedOverlay: LinearLayout = v.findViewById(R.id.linearLayout) + val iv_sync_status: ImageView = v.findViewById(R.id.iv_sync_status) + } +} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/OfflineDashboardAdapter.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/OfflineDashboardAdapter.java deleted file mode 100644 index 7607bc96eb0..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/OfflineDashboardAdapter.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.mifos.mifosxdroid.adapters; - -import androidx.recyclerview.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; - -import com.mifos.mifosxdroid.R; - -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Inject; - -import butterknife.BindView; -import butterknife.ButterKnife; - -/** - * Created by Rajan Maurya on 20/07/16. - */ -public class OfflineDashboardAdapter extends - RecyclerView.Adapter { - - private List payloadNames; - private List payloadCounts; - - - @Inject - public OfflineDashboardAdapter() { - payloadNames = new ArrayList<>(); - payloadCounts = new ArrayList<>(); - } - - @Override - public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_offline_dashboard, parent, false); - return new ViewHolder(view); - } - - @Override - public void onBindViewHolder(ViewHolder holder, int position) { - holder.tv_payload_name.setText(payloadNames.get(position)); - holder.tv_item_count.setText(payloadCounts.get(position)); - } - - @Override - public int getItemCount() { - return payloadNames.size(); - } - - public void showCard(String clientPayloadCount, int cardName) { - payloadCounts.add(clientPayloadCount); - payloadNames.add(cardName); - notifyDataSetChanged(); - } - - public void removeAllCards() { - payloadNames.clear(); - payloadCounts.clear(); - notifyDataSetChanged(); - } - - public static class ViewHolder extends RecyclerView.ViewHolder { - - @BindView(R.id.tv_payload_count) - TextView tv_item_count; - - @BindView(R.id.tv_payload_name) - TextView tv_payload_name; - - @BindView(R.id.iv_payload_image) - ImageView iv_payload_image; - - public ViewHolder(View v) { - super(v); - ButterKnife.bind(this, v); - } - } -} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/OfflineDashboardAdapter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/OfflineDashboardAdapter.kt new file mode 100644 index 00000000000..666a2c380fd --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/OfflineDashboardAdapter.kt @@ -0,0 +1,56 @@ +package com.mifos.mifosxdroid.adapters + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.mifos.mifosxdroid.R +import javax.inject.Inject + + +class OfflineDashboardAdapter( + val onItemClick: (Int) -> Unit +) : RecyclerView.Adapter() { + private val payloadNames: MutableList = ArrayList() + private val payloadCounts: MutableList = ArrayList() + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val viewHolder = ViewHolder( + LayoutInflater.from(parent.context) + .inflate(R.layout.item_offline_dashboard, parent, false) + ) + viewHolder.itemView.setOnClickListener { + if(viewHolder.adapterPosition != RecyclerView.NO_POSITION) + onItemClick(viewHolder.adapterPosition) + } + return viewHolder + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + holder.tv_payload_name.setText(payloadNames[position]) + holder.tv_item_count.text = payloadCounts[position] + } + + override fun getItemCount() = payloadNames.size + + + fun showCard(clientPayloadCount: String, cardName: Int) { + payloadCounts.add(clientPayloadCount) + payloadNames.add(cardName) + notifyDataSetChanged() + } + + fun removeAllCards() { + payloadNames.clear() + payloadCounts.clear() + notifyDataSetChanged() + } + + class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { + val tv_item_count: TextView = v.findViewById(R.id.tv_payload_count) + val tv_payload_name: TextView = v.findViewById(R.id.tv_payload_name) + val iv_payload_image: ImageView = v.findViewById(R.id.iv_payload_image) + } +} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/PathTrackingAdapter.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/PathTrackingAdapter.java deleted file mode 100644 index 5af6e87c21d..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/PathTrackingAdapter.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.mifos.mifosxdroid.adapters; - -import android.content.Context; -import androidx.cardview.widget.CardView; -import androidx.recyclerview.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import com.google.android.gms.maps.CameraUpdateFactory; -import com.google.android.gms.maps.GoogleMap; -import com.google.android.gms.maps.MapView; -import com.google.android.gms.maps.MapsInitializer; -import com.google.android.gms.maps.OnMapReadyCallback; -import com.google.android.gms.maps.model.LatLng; -import com.google.android.gms.maps.model.MarkerOptions; -import com.google.android.gms.maps.model.PolylineOptions; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.mifos.mifosxdroid.R; -import com.mifos.objects.user.UserLatLng; -import com.mifos.objects.user.UserLocation; - -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Inject; - -import butterknife.BindView; -import butterknife.ButterKnife; - -/** - * Created by Rajan Maurya on 24/01/17. - */ -public class PathTrackingAdapter extends RecyclerView.Adapter { - - private List userLocations; - private List userLatLngs; - private Context context; - - @Inject - public PathTrackingAdapter() { - userLocations = new ArrayList<>(); - userLatLngs = new ArrayList<>(); - } - - @Override - public PathTrackingAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_pinpoint_location, parent, false); - return new PathTrackingAdapter.ViewHolder(view); - } - - @Override - public void onBindViewHolder(final PathTrackingAdapter.ViewHolder holder, int position) { - - UserLocation location = userLocations.get(position); - userLatLngs = getLatLngList(location.getLatlng()); - - holder.tvAddress.setText(location.getDate() + " from " + location.getStartTime() + " to " + - location.getStopTime()); - try { - holder.mvUserLocation.setTag(userLatLngs.get(0)); - } catch (IndexOutOfBoundsException e) { - /* Prevents crashing upon calling an item not in the list */ - } - - // Ensure the map has been initialised by the on map ready callback in ViewHolder. - // If it is not ready yet, it will be initialised with the NamedLocation set as its tag - // when the callback is received. - if (holder.map != null) { - // The map is already ready to be used - try { - setMapLocation(holder.map, userLatLngs.get(0)); - } catch (IndexOutOfBoundsException e) { - /* Prevents crashing upon calling an item not in the list */ - } - } - } - - public void setContext(Context context) { - this.context = context; - } - - public void setPathTracker(List userLocations) { - this.userLocations = userLocations; - notifyDataSetChanged(); - } - - public UserLocation getItem(int position) { - return this.userLocations.get(position); - } - - @Override - public long getItemId(int i) { - return 0; - } - - @Override - public int getItemCount() { - return userLocations.size(); - } - - @Override - public void onViewRecycled(PathTrackingAdapter.ViewHolder holder) { - // Cleanup MapView here - if (holder.map != null) { - holder.map.clear(); - holder.map.setMapType(GoogleMap.MAP_TYPE_NONE); - } - } - - private void setMapLocation(GoogleMap map, UserLatLng location) { - // Add a marker for this item and set the camera - PolylineOptions polylineOptions = new PolylineOptions(); - for (UserLatLng userLatLng : userLatLngs) { - polylineOptions.add(new LatLng(userLatLng.getLat(), userLatLng.getLng())); - } - map.addPolyline(polylineOptions); - LatLng startLatLng = new LatLng(location.getLat(), location.getLng()); - LatLng stopLatLng = new LatLng(userLatLngs.get(userLatLngs.size() - 1).getLat(), - userLatLngs.get(userLatLngs.size() - 1).getLng()); - map.moveCamera(CameraUpdateFactory.newLatLngZoom(startLatLng, 13f)); - map.addMarker(new MarkerOptions().position(startLatLng)); - map.addMarker(new MarkerOptions().position(stopLatLng)); - // Set the map type back to normal. - map.setMapType(GoogleMap.MAP_TYPE_NORMAL); - } - - public class ViewHolder extends RecyclerView.ViewHolder implements OnMapReadyCallback { - - @BindView(R.id.mv_client_location) - MapView mvUserLocation; - - @BindView(R.id.tv_address) - TextView tvAddress; - - @BindView(R.id.card_view) - CardView cardView; - - GoogleMap map; - - public ViewHolder(View v) { - super(v); - ButterKnife.bind(this, v); - initializeMapView(); - } - - @Override - public void onMapReady(GoogleMap googleMap) { - MapsInitializer.initialize(context); - map = googleMap; - UserLatLng data = (UserLatLng) mvUserLocation.getTag(); - if (data != null) { - setMapLocation(map, data); - } - } - - /** - * Initialises the MapView by calling its lifecycle methods. - */ - public void initializeMapView() { - if (mvUserLocation != null) { - // Initialise the MapView - mvUserLocation.onCreate(null); - mvUserLocation.onResume(); - // Set the map ready callback to receive the GoogleMap object - mvUserLocation.getMapAsync(this); - } - } - } - - public List getLatLngList(String latLngString) { - Gson gson = new Gson(); - List latLngs = gson.fromJson(latLngString, - new TypeToken>() { - }.getType()); - return latLngs; - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/PathTrackingAdapter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/PathTrackingAdapter.kt new file mode 100644 index 00000000000..f70df752cad --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/PathTrackingAdapter.kt @@ -0,0 +1,138 @@ +package com.mifos.mifosxdroid.adapters + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.cardview.widget.CardView +import androidx.recyclerview.widget.RecyclerView +import com.google.android.gms.maps.* +import com.google.android.gms.maps.model.LatLng +import com.google.android.gms.maps.model.MarkerOptions +import com.google.android.gms.maps.model.PolylineOptions +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.mifos.mifosxdroid.R +import com.mifos.objects.user.UserLatLng +import com.mifos.objects.user.UserLocation + + +class PathTrackingAdapter( + val onUserLocationClick: (UserLocation) -> Unit +) :RecyclerView.Adapter() { + + private var userLocations: List = ArrayList() + private var userLatLngs: List = ArrayList() + + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val viewHolder = ViewHolder( + LayoutInflater.from(parent.context) + .inflate(R.layout.item_pinpoint_location, parent, false) + ) + viewHolder.itemView.setOnClickListener { + if(viewHolder.adapterPosition != RecyclerView.NO_POSITION) + onUserLocationClick(userLocations[viewHolder.adapterPosition]) + } + return viewHolder + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val location = userLocations[position] + userLatLngs = getLatLngList(location.latlng) + holder.tvAddress.text = location.date + " from " + location.startTime + " to " + location.stopTime + try { + holder.mvUserLocation.tag = userLatLngs[0] + } catch (e: IndexOutOfBoundsException) { + /* Prevents crashing upon calling an item not in the list */ + } + + // Ensure the map has been initialised by the on map ready callback in ViewHolder. + // If it is not ready yet, it will be initialised with the NamedLocation set as its tag + // when the callback is received. + if (holder.map != null) { + // The map is already ready to be used + try { + setMapLocation(holder.map, userLatLngs[0]) + } catch (e: IndexOutOfBoundsException) { + /* Prevents crashing upon calling an item not in the list */ + } + } + } + + fun setPathTracker(userLocations: List) { + this.userLocations = userLocations + notifyDataSetChanged() + } + + fun getItem(position: Int) = userLocations[position] + + + override fun getItemId(i: Int) = 0L + + override fun getItemCount() = userLocations.size + + override fun onViewRecycled(holder: ViewHolder) { + // Cleanup MapView here + if (holder.map != null) { + holder.map!!.clear() + holder.map!!.mapType = GoogleMap.MAP_TYPE_NONE + } + } + + private fun setMapLocation(map: GoogleMap?, location: UserLatLng) { + // Add a marker for this item and set the camera + val polylineOptions = PolylineOptions() + for (userLatLng in userLatLngs) { + polylineOptions.add(LatLng(userLatLng.lat, userLatLng.lng)) + } + map!!.addPolyline(polylineOptions) + val startLatLng = LatLng(location.lat, location.lng) + val stopLatLng = LatLng( + userLatLngs[userLatLngs.size - 1].lat, + userLatLngs[userLatLngs.size - 1].lng + ) + map.moveCamera(CameraUpdateFactory.newLatLngZoom(startLatLng, 13f)) + map.addMarker(MarkerOptions().position(startLatLng)) + map.addMarker(MarkerOptions().position(stopLatLng)) + // Set the map type back to normal. + map.mapType = GoogleMap.MAP_TYPE_NORMAL + } + + inner class ViewHolder(val v: View) : RecyclerView.ViewHolder(v), OnMapReadyCallback { + val mvUserLocation: MapView = v.findViewById(R.id.mv_client_location) + val tvAddress: TextView = v.findViewById(R.id.tv_address) + val cardView: CardView = v.findViewById(R.id.card_view) + var map: GoogleMap? = null + + init { + initializeMapView() + } + + override fun onMapReady(googleMap: GoogleMap) { + MapsInitializer.initialize(v.context) + map = googleMap + val data = mvUserLocation.tag as UserLatLng + setMapLocation(map, data) + } + + /** + * Initialises the MapView by calling its lifecycle methods. + */ + fun initializeMapView() { + // Initialise the MapView + mvUserLocation.onCreate(null) + mvUserLocation.onResume() + // Set the map ready callback to receive the GoogleMap object + mvUserLocation.getMapAsync(this) + } + } + + fun getLatLngList(latLngString: String?): List { + val gson = Gson() + return gson.fromJson( + latLngString, + object : TypeToken?>() {}.type + ) + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/SearchAdapter.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/SearchAdapter.java deleted file mode 100755 index 788007c1834..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/SearchAdapter.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ - -package com.mifos.mifosxdroid.adapters; - -import androidx.recyclerview.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; - -import com.amulyakhare.textdrawable.TextDrawable; -import com.amulyakhare.textdrawable.util.ColorGenerator; -import com.mifos.mifosxdroid.R; -import com.mifos.objects.SearchedEntity; - -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Inject; - -import butterknife.BindView; -import butterknife.ButterKnife; - -/** - * @author fomenkoo - */ -public class SearchAdapter extends RecyclerView.Adapter { - - private ColorGenerator mColorGenerator = ColorGenerator.MATERIAL; - private TextDrawable.IBuilder mDrawableBuilder; - private List searchedResults; - - @Inject - public SearchAdapter() { - mDrawableBuilder = TextDrawable.builder().round(); - searchedResults = new ArrayList<>(); - } - - @Override - public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - RecyclerView.ViewHolder vh; - View v = LayoutInflater.from(parent.getContext()).inflate( - R.layout.list_item_client, parent, false); - vh = new ViewHolder(v); - return vh; - } - - @Override - public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { - if (holder instanceof SearchAdapter.ViewHolder) { - SearchedEntity searchedEntity = searchedResults.get(position); - ((ViewHolder) holder).tv_name.setText(searchedEntity.getDescription()); - - TextDrawable drawable; - if (searchedEntity.getEntityName() != null && - searchedEntity.getEntityName().trim().length() > 0) { - drawable = mDrawableBuilder.build(String.valueOf( - searchedEntity.getEntityType().charAt(0)), - mColorGenerator.getColor(searchedEntity.getEntityType())); - ((ViewHolder) holder).iv_icon.setImageDrawable(drawable); - } - } - } - - @Override - public int getItemCount() { - return searchedResults.size(); - } - - public void setSearchResults(List searchedResults) { - this.searchedResults = searchedResults; - notifyDataSetChanged(); - } - - public static class ViewHolder extends RecyclerView.ViewHolder { - - @BindView(R.id.tv_icon) - ImageView iv_icon; - - @BindView(R.id.tv_name) - TextView tv_name; - - public ViewHolder(View v) { - super(v); - ButterKnife.bind(this, v); - } - } -} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/SearchAdapter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/SearchAdapter.kt new file mode 100644 index 00000000000..b77ef26605f --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/SearchAdapter.kt @@ -0,0 +1,61 @@ +package com.mifos.mifosxdroid.adapters + + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.amulyakhare.textdrawable.TextDrawable +import com.amulyakhare.textdrawable.TextDrawable.IBuilder +import com.amulyakhare.textdrawable.util.ColorGenerator +import com.mifos.mifosxdroid.R +import com.mifos.objects.SearchedEntity +import javax.inject.Inject + + +class SearchAdapter( + val onSearchItemClick: (SearchedEntity) -> Unit +) : RecyclerView.Adapter() { + private val mColorGenerator = ColorGenerator.MATERIAL + private var mDrawableBuilder: IBuilder = TextDrawable.builder().round() + private var searchedResults: List = ArrayList() + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val viewHolder = ViewHolder( + LayoutInflater.from(parent.context) + .inflate(R.layout.list_item_client, parent, false) + ) + viewHolder.itemView.setOnClickListener { + if(viewHolder.adapterPosition != RecyclerView.NO_POSITION) + onSearchItemClick(searchedResults[viewHolder.adapterPosition]) + } + return viewHolder + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val searchedEntity = searchedResults[position] + holder.tvName.text = searchedEntity.description + if (!searchedEntity.entityName.isNullOrBlank()) { + val drawable = mDrawableBuilder.build( + searchedEntity.entityType[0].toString(), + mColorGenerator.getColor(searchedEntity.entityType) + ) + holder.ivIcon.setImageDrawable(drawable) + } + } + + override fun getItemCount() = searchedResults.size + + + fun setSearchResults(searchedResults: List) { + this.searchedResults = searchedResults + notifyDataSetChanged() + } + + class ViewHolder(v: View) : RecyclerView.ViewHolder(v) { + val ivIcon: ImageView = v.findViewById(R.id.tv_icon) + val tvName: TextView = v.findViewById(R.id.tv_name) + } +} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/core/RecyclerItemClickListener.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/core/RecyclerItemClickListener.java deleted file mode 100644 index d6e02d9814f..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/core/RecyclerItemClickListener.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.mifos.mifosxdroid.core; - -import android.content.Context; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; -import android.view.GestureDetector; -import android.view.MotionEvent; -import android.view.View; - -/** - * Created by rajanmaurya on 16/4/2016. - */ -public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener { - - protected OnItemClickListener listener; - - private GestureDetector gestureDetector; - - @Nullable - private View childView; - - private int childViewPosition; - - public RecyclerItemClickListener(Context context, OnItemClickListener listener) { - this.gestureDetector = new GestureDetector(context, new GestureListener()); - this.listener = listener; - } - - @Override - public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent event) { - childView = view.findChildViewUnder(event.getX(), event.getY()); - childViewPosition = view.getChildAdapterPosition(childView); - - return childView != null && gestureDetector.onTouchEvent(event); - } - - @Override - public void onTouchEvent(RecyclerView view, MotionEvent event) { - // Not needed. - } - - @Override - public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { - - } - - /** - * A click listener for items. - */ - public interface OnItemClickListener { - - /** - * Called when an item is clicked. - * - * @param childView View of the item that was clicked. - * @param position Position of the item that was clicked. - */ - void onItemClick(View childView, int position); - - /** - * Called when an item is long pressed. - * - * @param childView View of the item that was long pressed. - * @param position Position of the item that was long pressed. - */ - void onItemLongPress(View childView, int position); - - } - - /** - * A simple click listener whose methods can be overridden one by one. - */ - public abstract static class SimpleOnItemClickListener implements OnItemClickListener { - - /** - * Called when an item is clicked. The default implementation is a no-op. - * - * @param childView View of the item that was clicked. - * @param position Position of the item that was clicked. - */ - public void onItemClick(View childView, int position) { - // Do nothing. - } - - /** - * Called when an item is long pressed. The default implementation is a no-op. - * - * @param childView View of the item that was long pressed. - * @param position Position of the item that was long pressed. - */ - public void onItemLongPress(View childView, int position) { - // Do nothing. - } - - } - - protected class GestureListener extends GestureDetector.SimpleOnGestureListener { - - @Override - public boolean onSingleTapUp(MotionEvent event) { - if (childView != null) { - listener.onItemClick(childView, childViewPosition); - } - - return true; - } - - @Override - public void onLongPress(MotionEvent event) { - if (childView != null) { - listener.onItemLongPress(childView, childViewPosition); - } - } - - @Override - public boolean onDown(MotionEvent event) { - // Best practice to always return true here. - // http://developer.android.com/training/gestures/detector.html#detect - return true; - } - - } - -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/checkertaskfilterdialog/CheckerTaskFilterDialogFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/checkertaskfilterdialog/CheckerTaskFilterDialogFragment.kt index 08e82fe21eb..1d0dddb13aa 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/checkertaskfilterdialog/CheckerTaskFilterDialogFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/checkertaskfilterdialog/CheckerTaskFilterDialogFragment.kt @@ -125,12 +125,12 @@ class CheckerTaskFilterDialogFragment : DialogFragment(), MFDatePicker.OnDatePic actionOptionsList.addAll(checkerInboxSearchTemplate.actionNames) entityOptionsList.addAll(checkerInboxSearchTemplate.entityNames) - actionOptionsAdapter = ArrayAdapter(activity, + actionOptionsAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, actionOptionsList) actionOptionsAdapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item) - entityOptionsAdapter = ArrayAdapter(activity, + entityOptionsAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, entityOptionsList) entityOptionsAdapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item) @@ -148,7 +148,7 @@ class CheckerTaskFilterDialogFragment : DialogFragment(), MFDatePicker.OnDatePic try { mOnInputSelected = targetFragment as OnInputSelected } catch (e: ClassCastException) { - Log.e("TaskFilterDialog", e.message) + Log.e("TaskFilterDialog", e.message.toString()) } } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/offlinedashbarod/OfflineDashboardFragment.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/offlinedashbarod/OfflineDashboardFragment.java index cfbf1244bbf..dfed8f80cdc 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/offlinedashbarod/OfflineDashboardFragment.java +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/offlinedashbarod/OfflineDashboardFragment.java @@ -2,10 +2,6 @@ import android.content.Intent; import android.os.Bundle; -import androidx.recyclerview.widget.DefaultItemAnimator; -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -18,15 +14,12 @@ import com.mifos.mifosxdroid.adapters.OfflineDashboardAdapter; import com.mifos.mifosxdroid.core.MifosBaseActivity; import com.mifos.mifosxdroid.core.MifosBaseFragment; -import com.mifos.mifosxdroid.core.RecyclerItemClickListener; import com.mifos.mifosxdroid.core.util.Toaster; import com.mifos.mifosxdroid.offline.synccenterpayloads.SyncCenterPayloadActivity; import com.mifos.mifosxdroid.offline.syncclientpayloads.SyncClientPayloadActivity; import com.mifos.mifosxdroid.offline.syncgrouppayloads.SyncGroupPayloadsActivity; import com.mifos.mifosxdroid.offline.syncloanrepaymenttransacition.SyncLoanRepaymentTransactionActivity; - -import com.mifos.mifosxdroid.offline.syncsavingsaccounttransaction - .SyncSavingsAccountTransactionActivity; +import com.mifos.mifosxdroid.offline.syncsavingsaccounttransaction.SyncSavingsAccountTransactionActivity; import com.mifos.objects.accounts.loan.LoanRepaymentRequest; import com.mifos.objects.accounts.savings.SavingsAccountTransactionRequest; import com.mifos.objects.client.ClientPayload; @@ -39,6 +32,10 @@ import javax.inject.Inject; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import butterknife.BindView; import butterknife.ButterKnife; @@ -63,8 +60,7 @@ * * Created by Rajan Maurya on 20/07/16. */ -public class OfflineDashboardFragment extends MifosBaseFragment implements - OfflineDashboardMvpView, RecyclerItemClickListener.OnItemClickListener { +public class OfflineDashboardFragment extends MifosBaseFragment implements OfflineDashboardMvpView { public final String LOG_TAG = getClass().getSimpleName(); @@ -88,7 +84,6 @@ public class OfflineDashboardFragment extends MifosBaseFragment implements @Inject OfflineDashboardPresenter mOfflineDashboardPresenter; - @Inject OfflineDashboardAdapter mOfflineDashboardAdapter; // update mPayloadIndex to number of request is going to fetch data in Presenter; @@ -104,17 +99,6 @@ public class OfflineDashboardFragment extends MifosBaseFragment implements R.string.sync_loanrepayments, R.string.sync_savingsaccounttransactions}; - - @Override - public void onItemClick(View childView, int position) { - startPayloadActivity(mPayloadClasses.get(position)); - } - - @Override - public void onItemLongPress(View childView, int position) { - - } - public static OfflineDashboardFragment newInstance() { OfflineDashboardFragment fragment = new OfflineDashboardFragment(); Bundle args = new Bundle(); @@ -144,11 +128,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); rv_offline_dashboard.setLayoutManager(mLayoutManager); rv_offline_dashboard.setHasFixedSize(true); - rv_offline_dashboard.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), - this)); rv_offline_dashboard.setItemAnimator(new DefaultItemAnimator()); rv_offline_dashboard.addItemDecoration(new ItemOffsetDecoration(getActivity(), R.dimen.item_offset)); + mOfflineDashboardAdapter = new OfflineDashboardAdapter(position -> { + startPayloadActivity(mPayloadClasses.get(position)); + return null; + }); rv_offline_dashboard.setAdapter(mOfflineDashboardAdapter); return rootView; diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/ClientActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/ClientActivity.kt index 2bfcbe02451..2a2dc804937 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/ClientActivity.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/ClientActivity.kt @@ -33,9 +33,11 @@ class ClientActivity : MifosBaseActivity(), ClientDetailsFragment.OnFragmentInte setContentView(R.layout.activity_toolbar_container) ButterKnife.bind(this) showBackButton() - clientId = intent.extras.getInt(Constants.CLIENT_ID) - loanAccountNumber = intent.extras.getInt(Constants.LOAN_ACCOUNT_NUMBER) - savingsAccountNumber = intent.extras.getInt(Constants.SAVINGS_ACCOUNT_NUMBER) + intent.extras?.let { extras -> + clientId = extras.getInt(Constants.CLIENT_ID) + loanAccountNumber = extras.getInt(Constants.LOAN_ACCOUNT_NUMBER) + savingsAccountNumber = extras.getInt(Constants.SAVINGS_ACCOUNT_NUMBER) + } val depositType = DepositType() depositType.id = 100 depositType.value = Constants.ENTITY_TYPE_SAVINGS diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/GenerateCollectionSheetActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/GenerateCollectionSheetActivity.kt index 50a3d54382d..fa2c92145d0 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/GenerateCollectionSheetActivity.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/GenerateCollectionSheetActivity.kt @@ -20,16 +20,11 @@ class GenerateCollectionSheetActivity : MifosBaseActivity(), OnPayloadSelectedLi super.onCreate(savedInstanceState) setContentView(R.layout.activity_toolbar_container) showBackButton() - val fragmentToOpen: String - if (intent != null) { - fragmentToOpen = intent.getStringExtra(Constants.COLLECTION_TYPE) - if (fragmentToOpen == Constants.EXTRA_COLLECTION_INDIVIDUAL) { - replaceFragment(IndividualCollectionSheetFragment.newInstance(), - false, R.id.container) - } else if (fragmentToOpen == Constants.EXTRA_COLLECTION_COLLECTION) { - replaceFragment(GenerateCollectionSheetFragment.newInstance(), - false, R.id.container) - } + intent?.getStringExtra(Constants.COLLECTION_TYPE)?.let { collectionType -> + if(collectionType == Constants.EXTRA_COLLECTION_INDIVIDUAL) + replaceFragment(IndividualCollectionSheetFragment.newInstance(),false, R.id.container) + else if(collectionType == Constants.EXTRA_COLLECTION_COLLECTION) + replaceFragment(GenerateCollectionSheetFragment.newInstance(),false, R.id.container) } } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/GroupsActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/GroupsActivity.kt index d3bf2bca75c..c274065b97b 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/GroupsActivity.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/GroupsActivity.kt @@ -28,7 +28,7 @@ class GroupsActivity : MifosBaseActivity(), GroupDetailsFragment.OnFragmentInter setContentView(R.layout.activity_toolbar_container) ButterKnife.bind(this) showBackButton() - val groupId = intent.extras.getInt(Constants.GROUP_ID) + val groupId = intent.extras!!.getInt(Constants.GROUP_ID) replaceFragment(newInstance(groupId), false, R.id.container) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/SurveyQuestionFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/SurveyQuestionFragment.kt index cdfb4eb4276..f7be98764fc 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/SurveyQuestionFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/SurveyQuestionFragment.kt @@ -41,7 +41,7 @@ class SurveyQuestionFragment : MifosBaseFragment(), RadioGroup.OnCheckedChangeLi private var mScorecardValues: ScorecardValues? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - mQuestionDatas = Gson().fromJson(arguments!!.getString(Constants.QUESTION_DATA), + mQuestionDatas = Gson().fromJson(requireArguments().getString(Constants.QUESTION_DATA), QuestionDatas::class.java) mScorecardValues = ScorecardValues() } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsFragment.kt index d1218a54ad5..e69fa11a875 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsFragment.kt @@ -87,7 +87,7 @@ class CenterDetailsFragment : MifosBaseFragment(), CenterDetailsMvpView { super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) if (arguments != null) { - centerId = arguments!!.getInt(Constants.CENTER_ID) + centerId = requireArguments().getInt(Constants.CENTER_ID) } setHasOptionsMenu(true) } @@ -104,7 +104,7 @@ class CenterDetailsFragment : MifosBaseFragment(), CenterDetailsMvpView { @OnClick(R.id.btn_activate_center) fun onClickActivateCenter() { val activateFragment = ActivateFragment.newInstance(centerId, Constants.ACTIVATE_CENTER) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CENTER_DETAIL) fragmentTransaction.replace(R.id.container, activateFragment) diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListFragment.kt index 98dedcf147c..3d1246e66ed 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListFragment.kt @@ -22,7 +22,6 @@ import com.mifos.mifosxdroid.adapters.CentersListAdapter import com.mifos.mifosxdroid.core.EndlessRecyclerViewScrollListener import com.mifos.mifosxdroid.core.MifosBaseActivity import com.mifos.mifosxdroid.core.MifosBaseFragment -import com.mifos.mifosxdroid.core.RecyclerItemClickListener import com.mifos.mifosxdroid.core.util.Toaster import com.mifos.mifosxdroid.dialogfragments.synccenterdialog.SyncCentersDialogFragment import com.mifos.mifosxdroid.online.CentersActivity @@ -43,7 +42,7 @@ import javax.inject.Inject * CenterListFragment Fetching and Showing CenterList in RecyclerView from * >demo.openmf.org/fineract-provider/api/v1/centers?paged=true&offset=0&limit=100> */ -class CenterListFragment : MifosBaseFragment(), CenterListMvpView, RecyclerItemClickListener.OnItemClickListener, OnRefreshListener { +class CenterListFragment : MifosBaseFragment(), CenterListMvpView, OnRefreshListener { @JvmField @BindView(R.id.rv_center_list) var rvCenters: RecyclerView? = null @@ -64,8 +63,7 @@ class CenterListFragment : MifosBaseFragment(), CenterListMvpView, RecyclerItemC @Inject var mCenterListPresenter: CenterListPresenter? = null - @JvmField - @Inject + var centersListAdapter: CentersListAdapter? = null private lateinit var rootView: View private var centers: List
? = null @@ -74,22 +72,6 @@ class CenterListFragment : MifosBaseFragment(), CenterListMvpView, RecyclerItemC private var actionModeCallback: ActionModeCallback? = null private var actionMode: ActionMode? = null private var sweetUIErrorHandler: SweetUIErrorHandler? = null - override fun onItemClick(childView: View, position: Int) { - if (actionMode != null) { - toggleSelection(position) - } else { - val centerIntent = Intent(activity, CentersActivity::class.java) - centerIntent.putExtra(Constants.CENTER_ID, centers!![position].id) - startActivity(centerIntent) - } - } - - override fun onItemLongPress(childView: View, position: Int) { - if (actionMode == null) { - actionMode = (activity as MifosBaseActivity?)!!.startSupportActionMode(actionModeCallback!!) - } - toggleSelection(position) - } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -131,12 +113,26 @@ class CenterListFragment : MifosBaseFragment(), CenterListMvpView, RecyclerItemC layoutManager = LinearLayoutManager(activity) layoutManager!!.orientation = LinearLayoutManager.VERTICAL rvCenters!!.layoutManager = layoutManager - rvCenters!!.addOnItemTouchListener(RecyclerItemClickListener(activity, this)) + centersListAdapter = CentersListAdapter( + onCenterClick = { position -> + if (actionMode != null) { + toggleSelection(position) + } else { + val centerIntent = Intent(activity, CentersActivity::class.java) + centerIntent.putExtra(Constants.CENTER_ID, centers!![position].id) + startActivity(centerIntent) + } + }, + onCenterLongClick = { position -> + if (actionMode == null) + actionMode = (activity as MifosBaseActivity?)!!.startSupportActionMode(actionModeCallback!!) + toggleSelection(position) + } + ) rvCenters!!.setHasFixedSize(true) - centersListAdapter!!.setContext(activity) rvCenters!!.adapter = centersListAdapter swipeRefreshLayout!!.setColorSchemeColors(*activity - ?.getResources()!!.getIntArray(R.array.swipeRefreshColors)) + ?.resources!!.getIntArray(R.array.swipeRefreshColors)) swipeRefreshLayout!!.setOnRefreshListener(this) sweetUIErrorHandler = SweetUIErrorHandler(activity, rootView) } @@ -173,7 +169,7 @@ class CenterListFragment : MifosBaseFragment(), CenterListMvpView, RecyclerItemC
*/ override fun showCenters(centers: List?) { this.centers = centers as List
? - centersListAdapter!!.setCenters(centers) + centersListAdapter!!.setCenters(this.centers ?: emptyList()) centersListAdapter!!.notifyDataSetChanged() } @@ -224,7 +220,7 @@ class CenterListFragment : MifosBaseFragment(), CenterListMvpView, RecyclerItemC showMessage(R.string.no_meeting_found) } } - mfDatePicker.show(activity!!.supportFragmentManager, MFDatePicker.TAG) + mfDatePicker.show(requireActivity().supportFragmentManager, MFDatePicker.TAG) } /** @@ -263,7 +259,7 @@ class CenterListFragment : MifosBaseFragment(), CenterListMvpView, RecyclerItemC } override fun onOptionsItemSelected(item: MenuItem): Boolean { - if (item.itemId == R.id.mItem_search) activity!!.finish() + if (item.itemId == R.id.mItem_search) requireActivity().finish() return super.onOptionsItemSelected(item) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/checkerinbox/CheckerInboxFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/checkerinbox/CheckerInboxFragment.kt index a5e71bf8090..cfaa1d0cecc 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/checkerinbox/CheckerInboxFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/checkerinbox/CheckerInboxFragment.kt @@ -322,6 +322,7 @@ class CheckerInboxFragment : MifosBaseFragment(), TextWatcher, showNetworkError() } } + else -> {} } } @@ -331,7 +332,7 @@ class CheckerInboxFragment : MifosBaseFragment(), TextWatcher, iv_filter_search_icon.setOnClickListener { val dialogSearchFilter = CheckerTaskFilterDialogFragment() dialogSearchFilter.setTargetFragment(this@CheckerInboxFragment, 1) - dialogSearchFilter.show(activity!!.supportFragmentManager, "DialogSearchFilter") + dialogSearchFilter.show(requireActivity().supportFragmentManager, "DialogSearchFilter") } iv_batch_approve_icon.setOnClickListener { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/checkerinbox/CheckerInboxTasksFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/checkerinbox/CheckerInboxTasksFragment.kt index d28cf2646e7..6a8f3a0de66 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/checkerinbox/CheckerInboxTasksFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/checkerinbox/CheckerInboxTasksFragment.kt @@ -79,7 +79,7 @@ class CheckerInboxTasksFragment : MifosBaseFragment(), SwipeRefreshLayout.OnRefr }) rl_checker_inbox.setOnClickListener { - val fragmentTransaction = activity!! + val fragmentTransaction = requireActivity() .supportFragmentManager.beginTransaction() fragmentTransaction.addToBackStack("Checker Inbox") fragmentTransaction.replace(R.id.container, diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeFragment.kt index 68114e40cd2..77a9e94a406 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeFragment.kt @@ -21,7 +21,6 @@ import com.mifos.mifosxdroid.adapters.ChargeNameListAdapter import com.mifos.mifosxdroid.core.EndlessRecyclerOnScrollListener import com.mifos.mifosxdroid.core.MifosBaseActivity import com.mifos.mifosxdroid.core.MifosBaseFragment -import com.mifos.mifosxdroid.core.RecyclerItemClickListener import com.mifos.mifosxdroid.core.util.Toaster import com.mifos.mifosxdroid.dialogfragments.chargedialog.ChargeDialogFragment import com.mifos.mifosxdroid.dialogfragments.chargedialog.OnChargeCreateListener @@ -35,7 +34,7 @@ import javax.inject.Inject /** * Created by nellyk on 1/22/2016. */ -class ClientChargeFragment : MifosBaseFragment(), ClientChargeMvpView, RecyclerItemClickListener.OnItemClickListener, OnChargeCreateListener { +class ClientChargeFragment : MifosBaseFragment(), ClientChargeMvpView, OnChargeCreateListener { @JvmField @BindView(R.id.rv_charge) var rv_charges: RecyclerView? = null @@ -65,12 +64,10 @@ class ClientChargeFragment : MifosBaseFragment(), ClientChargeMvpView, RecyclerI private var clientId = 0 private var mApiRestCounter = 0 private val limit = 10 - override fun onItemClick(childView: View, position: Int) {} - override fun onItemLongPress(childView: View, position: Int) {} override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) - if (arguments != null) clientId = arguments!!.getInt(Constants.CLIENT_ID) + if (arguments != null) clientId = requireArguments().getInt(Constants.CLIENT_ID) } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -81,7 +78,6 @@ class ClientChargeFragment : MifosBaseFragment(), ClientChargeMvpView, RecyclerI val layoutManager = LinearLayoutManager(activity) layoutManager.orientation = LinearLayoutManager.VERTICAL rv_charges!!.layoutManager = layoutManager - rv_charges!!.addOnItemTouchListener(RecyclerItemClickListener(activity, this)) rv_charges!!.setHasFixedSize(true) setToolbarTitle(getString(R.string.charges)) mApiRestCounter = 1 @@ -135,8 +131,7 @@ class ClientChargeFragment : MifosBaseFragment(), ClientChargeMvpView, RecyclerI */ if (mApiRestCounter == 1) { chargesList = chargesPage!!.pageItems as ArrayList - mChargesNameListAdapter = ChargeNameListAdapter(activity, - chargesList, clientId) + mChargesNameListAdapter = ChargeNameListAdapter(chargesList, clientId) rv_charges!!.adapter = mChargesNameListAdapter ll_error!!.visibility = View.GONE } else { @@ -158,8 +153,7 @@ class ClientChargeFragment : MifosBaseFragment(), ClientChargeMvpView, RecyclerI } //If the adapter has not been initialized, there were 0 charge items earlier. Initialize it. if (mChargesNameListAdapter == null) { - mChargesNameListAdapter = ChargeNameListAdapter(activity, - chargesList, clientId) + mChargesNameListAdapter = ChargeNameListAdapter(chargesList, clientId) rv_charges!!.adapter = mChargesNameListAdapter } mChargesNameListAdapter!!.notifyItemInserted(chargesList.size - 1) @@ -216,7 +210,7 @@ class ClientChargeFragment : MifosBaseFragment(), ClientChargeMvpView, RecyclerI if (id == MENU_ITEM_ADD_NEW_CHARGES) { val chargeDialogFragment = ChargeDialogFragment.newInstance(clientId) chargeDialogFragment.setOnChargeCreatedListener(this) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CHARGE_LIST) chargeDialogFragment.show(fragmentTransaction, "Charge Dialog Fragment") diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsFragment.kt index 9cb47c682eb..80dac5e0d53 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsFragment.kt @@ -154,7 +154,7 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView { super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) if (arguments != null) { - clientId = arguments!!.getInt(Constants.CLIENT_ID) + clientId = requireArguments().getInt(Constants.CLIENT_ID) } setHasOptionsMenu(true) checkPermissions() @@ -191,15 +191,15 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView { super.onActivityResult(requestCode, resultCode, data) try { // When an Image is picked - if (requestCode == UPLOAD_IMAGE_ACTIVITY_REQUEST_CODE && resultCode == Activity.RESULT_OK && null != data) { + if (requestCode == UPLOAD_IMAGE_ACTIVITY_REQUEST_CODE && resultCode == Activity.RESULT_OK && null != data && data.data != null) { // Get the Image from data - val selectedImage = data.data + val selectedImage = data.data!! val filePathColumn = arrayOf(MediaStore.Images.Media.DATA) // Get the cursor - val cursor = activity!!.applicationContext.contentResolver.query( + val cursor = requireActivity().applicationContext.contentResolver.query( selectedImage, - filePathColumn, null, null, null) + filePathColumn, null, null, null)!! // Move to first row cursor.moveToFirst() val columnIndex = cursor.getColumnIndex(filePathColumn[0]) @@ -282,10 +282,10 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView { } private fun checkPermissions() { - if (ContextCompat.checkSelfPermission(activity!!, + if (ContextCompat.checkSelfPermission(requireActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { - ActivityCompat.requestPermissions(activity!!, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), + ActivityCompat.requestPermissions(requireActivity(), arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), CHECK_PERMISSIONS) } } @@ -315,7 +315,7 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView { fun loadDocuments() { val documentListFragment = DocumentListFragment.newInstance(Constants.ENTITY_TYPE_CLIENTS, clientId) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CLIENT_DETAILS) fragmentTransaction.replace(R.id.container, documentListFragment) @@ -324,7 +324,7 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView { fun loadNotes() { val noteFragment = NoteFragment.newInstance(Constants.ENTITY_TYPE_CLIENTS, clientId) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CLIENT_DETAILS) fragmentTransaction.replace(R.id.container, noteFragment) @@ -334,7 +334,7 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView { fun loadClientCharges() { val clientChargeFragment: ClientChargeFragment = ClientChargeFragment.Companion.newInstance(clientId, chargesList) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CLIENT_DETAILS) fragmentTransaction.replace(R.id.container, clientChargeFragment) @@ -343,7 +343,7 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView { fun loadIdentifiers() { val clientIdentifiersFragment: ClientIdentifiersFragment = ClientIdentifiersFragment.Companion.newInstance(clientId) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CLIENT_DETAILS) fragmentTransaction.replace(R.id.container, clientIdentifiersFragment) @@ -352,7 +352,7 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView { fun loadSurveys() { val surveyListFragment = SurveyListFragment.newInstance(clientId) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CLIENT_DETAILS) fragmentTransaction.replace(R.id.container, surveyListFragment) @@ -361,7 +361,7 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView { fun addsavingsaccount() { val savingsAccountFragment = SavingsAccountFragment.newInstance(clientId, false) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CLIENT_DETAILS) fragmentTransaction.replace(R.id.container, savingsAccountFragment) @@ -370,7 +370,7 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView { fun addloanaccount() { val loanAccountFragment = LoanAccountFragment.newInstance(clientId) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CLIENT_DETAILS) fragmentTransaction.replace(R.id.container, loanAccountFragment) @@ -379,7 +379,7 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView { fun activateClient() { val activateFragment = ActivateFragment.newInstance(clientId, Constants.ACTIVATE_CLIENT) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CLIENT_DETAILS) fragmentTransaction.replace(R.id.container, activateFragment) @@ -388,7 +388,7 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView { fun loadClientDataTables() { val loanAccountFragment = DataTableFragment.newInstance(Constants.DATA_TABLE_NAME_CLIENT, clientId) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CLIENT_DETAILS) fragmentTransaction.replace(R.id.container, loanAccountFragment) @@ -400,7 +400,7 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView { val bundle = Bundle() bundle.putInt(Constants.CLIENT_ID, clientId) fragment.arguments = bundle - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CLIENT_DETAILS) fragmentTransaction.replace(R.id.container, fragment).commit() @@ -420,7 +420,7 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView { if (client != null) { setToolbarTitle(getString(R.string.client) + " - " + client.displayName) isClientActive = client.isActive - activity!!.invalidateOptionsMenu() + requireActivity().invalidateOptionsMenu() if (!client.isActive) { llBottomPanel!!.visibility = View.VISIBLE } @@ -453,7 +453,7 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView { pb_imageProgressBar!!.visibility = View.GONE } iv_clientImage!!.setOnClickListener { view -> - val menu = PopupMenu(activity!!, view) + val menu = PopupMenu(requireActivity(), view) menu.menuInflater.inflate(R.menu.client_image_popup, menu .menu) if (!client.isImagePresent) { @@ -502,7 +502,7 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView { override fun showClientImageDeletedSuccessfully() { Toaster.show(rootView, "Image deleted") - iv_clientImage!!.setImageDrawable(ContextCompat.getDrawable(activity!!, R.drawable.ic_launcher)) + iv_clientImage!!.setImageDrawable(ContextCompat.getDrawable(requireActivity(), R.drawable.ic_launcher)) } override fun showClientAccount(clientAccounts: ClientAccounts) { @@ -513,13 +513,13 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView { accountAccordion = AccountAccordion(activity) if (clientAccounts.loanAccounts.size > 0) { val section = AccountAccordion.Section.LOANS - val adapter = LoanAccountsListAdapter(activity!!.applicationContext, + val adapter = LoanAccountsListAdapter(requireActivity().applicationContext, clientAccounts.loanAccounts) section.connect(activity, adapter, AdapterView.OnItemClickListener { adapterView, view, i, l -> mListener!!.loadLoanAccountSummary(adapter.getItem(i).id) }) } if (clientAccounts.nonRecurringSavingsAccounts.size > 0) { val section = AccountAccordion.Section.SAVINGS - val adapter = SavingsAccountsListAdapter(activity!!.applicationContext, + val adapter = SavingsAccountsListAdapter(requireActivity().applicationContext, clientAccounts.nonRecurringSavingsAccounts) section.connect(activity, adapter, AdapterView.OnItemClickListener { adapterView, view, i, l -> mListener!!.loadSavingsAccountSummary(adapter.getItem(i).id, @@ -528,7 +528,7 @@ class ClientDetailsFragment : MifosBaseFragment(), ClientDetailsMvpView { } if (clientAccounts.recurringSavingsAccounts.size > 0) { val section = AccountAccordion.Section.RECURRING - val adapter = SavingsAccountsListAdapter(activity!!.applicationContext, + val adapter = SavingsAccountsListAdapter(requireActivity().applicationContext, clientAccounts.recurringSavingsAccounts) section.connect(activity, adapter, AdapterView.OnItemClickListener { adapterView, view, i, l -> mListener!!.loadSavingsAccountSummary(adapter.getItem(i).id, diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientidentifiers/ClientIdentifiersFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientidentifiers/ClientIdentifiersFragment.kt index 88110503a47..b20dab31bbc 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientidentifiers/ClientIdentifiersFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientidentifiers/ClientIdentifiersFragment.kt @@ -67,7 +67,7 @@ class ClientIdentifiersFragment : MifosBaseFragment(), ClientIdentifiersMvpView, super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) if (arguments != null) { - clientId = arguments!!.getInt(Constants.CLIENT_ID) + clientId = requireArguments().getInt(Constants.CLIENT_ID) } setHasOptionsMenu(true) } @@ -149,7 +149,7 @@ class ClientIdentifiersFragment : MifosBaseFragment(), ClientIdentifiersMvpView, val documentListFragment = DocumentListFragment.newInstance( Constants.ENTITY_TYPE_CLIENT_IDENTIFIERS, identifiers!![position].id) - val fragmentTransaction = activity!!.supportFragmentManager.beginTransaction() + val fragmentTransaction = requireActivity().supportFragmentManager.beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CLIENT_IDENTIFIER) fragmentTransaction.replace(R.id.container, documentListFragment) fragmentTransaction.commit() @@ -189,7 +189,7 @@ class ClientIdentifiersFragment : MifosBaseFragment(), ClientIdentifiersMvpView, R.id.menu_add -> { val identifierDialogFragment = IdentifierDialogFragment.newInstance(clientId) identifierDialogFragment.setOnClientIdentifierCreationListener(this) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_DOCUMENT_LIST) identifierDialogFragment.show(fragmentTransaction, "Identifier Dialog Fragment") diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListFragment.kt index 332d2d80672..a8dfe22a839 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListFragment.kt @@ -10,7 +10,6 @@ import android.os.Parcelable import android.view.* import android.widget.ProgressBar import androidx.appcompat.view.ActionMode -import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import androidx.swiperefreshlayout.widget.SwipeRefreshLayout @@ -24,7 +23,6 @@ import com.mifos.mifosxdroid.adapters.ClientNameListAdapter import com.mifos.mifosxdroid.core.EndlessRecyclerViewScrollListener import com.mifos.mifosxdroid.core.MifosBaseActivity import com.mifos.mifosxdroid.core.MifosBaseFragment -import com.mifos.mifosxdroid.core.RecyclerItemClickListener import com.mifos.mifosxdroid.core.util.Toaster import com.mifos.mifosxdroid.dialogfragments.syncclientsdialog.SyncClientsDialogFragment import com.mifos.mifosxdroid.online.ClientActivity @@ -32,7 +30,6 @@ import com.mifos.mifosxdroid.online.createnewclient.CreateNewClientFragment import com.mifos.objects.client.Client import com.mifos.utils.Constants import com.mifos.utils.FragmentConstants -import java.util.* import javax.inject.Inject /** @@ -59,7 +56,7 @@ import javax.inject.Inject * boolean isParentFragment) {...} * and unregister the ScrollListener and SwipeLayout. */ -class ClientListFragment : MifosBaseFragment(), RecyclerItemClickListener.OnItemClickListener, ClientListMvpView, OnRefreshListener { +class ClientListFragment : MifosBaseFragment(), ClientListMvpView, OnRefreshListener { @JvmField @BindView(R.id.rv_clients) var rv_clients: RecyclerView? = null @@ -76,9 +73,26 @@ class ClientListFragment : MifosBaseFragment(), RecyclerItemClickListener.OnItem @BindView(R.id.pb_client) var pb_client: ProgressBar? = null - @JvmField - @Inject - var mClientNameListAdapter: ClientNameListAdapter? = null + val mClientNameListAdapter by lazy { + ClientNameListAdapter( + onClientNameClick = { position -> + if (actionMode != null) { + toggleSelection(position) + } else { + val clientActivityIntent = Intent(activity, ClientActivity::class.java) + clientActivityIntent.putExtra(Constants.CLIENT_ID, clientList!![position].id) + startActivity(clientActivityIntent) + clickedPosition = position + } + }, + onClientNameLongClick = { position -> + if (actionMode == null) { + actionMode = (activity as MifosBaseActivity?)!!.startSupportActionMode(actionModeCallback!!) + } + toggleSelection(position) + } + ) + } @JvmField @Inject @@ -92,23 +106,6 @@ class ClientListFragment : MifosBaseFragment(), RecyclerItemClickListener.OnItem private var mLayoutManager: LinearLayoutManager? = null private var clickedPosition = -1 private var sweetUIErrorHandler: SweetUIErrorHandler? = null - override fun onItemClick(childView: View, position: Int) { - if (actionMode != null) { - toggleSelection(position) - } else { - val clientActivityIntent = Intent(activity, ClientActivity::class.java) - clientActivityIntent.putExtra(Constants.CLIENT_ID, clientList!![position].id) - startActivity(clientActivityIntent) - clickedPosition = position - } - } - - override fun onItemLongPress(childView: View, position: Int) { - if (actionMode == null) { - actionMode = (activity as MifosBaseActivity?)!!.startSupportActionMode(actionModeCallback!!) - } - toggleSelection(position) - } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -116,8 +113,8 @@ class ClientListFragment : MifosBaseFragment(), RecyclerItemClickListener.OnItem selectedClients = ArrayList() actionModeCallback = ActionModeCallback() if (arguments != null) { - clientList = arguments!!.getParcelableArrayList(Constants.CLIENTS) - isParentFragment = arguments!! + clientList = requireArguments().getParcelableArrayList(Constants.CLIENTS) + isParentFragment = requireArguments() .getBoolean(Constants.IS_A_PARENT_FRAGMENT) } setHasOptionsMenu(true) @@ -169,9 +166,7 @@ class ClientListFragment : MifosBaseFragment(), RecyclerItemClickListener.OnItem override fun showUserInterface() { mLayoutManager = LinearLayoutManager(activity) mLayoutManager!!.orientation = LinearLayoutManager.VERTICAL - mClientNameListAdapter!!.setContext(activity) rv_clients!!.layoutManager = mLayoutManager - rv_clients!!.addOnItemTouchListener(RecyclerItemClickListener(activity, this)) rv_clients!!.setHasFixedSize(true) rv_clients!!.adapter = mClientNameListAdapter swipeRefreshLayout!!.setColorSchemeColors(*activity @@ -231,7 +226,7 @@ class ClientListFragment : MifosBaseFragment(), RecyclerItemClickListener.OnItem */ override fun showClientList(clients: List?) { clientList = clients - mClientNameListAdapter!!.setClients(clients) + mClientNameListAdapter!!.setClients(clients ?: emptyList()) mClientNameListAdapter!!.notifyDataSetChanged() } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheet/CollectionSheetFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheet/CollectionSheetFragment.kt index d5620deda24..3afefb3df96 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheet/CollectionSheetFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheet/CollectionSheetFragment.kt @@ -58,9 +58,9 @@ class CollectionSheetFragment : MifosBaseFragment(), CollectionSheetMvpView { super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) if (arguments != null) { - centerId = arguments!!.getInt(Constants.CENTER_ID) - dateOfCollection = arguments!!.getString(Constants.DATE_OF_COLLECTION) - calendarInstanceId = arguments!!.getInt(Constants.CALENDAR_INSTANCE_ID) + centerId = requireArguments().getInt(Constants.CENTER_ID) + dateOfCollection = requireArguments().getString(Constants.DATE_OF_COLLECTION) + calendarInstanceId = requireArguments().getInt(Constants.CALENDAR_INSTANCE_ID) } setHasOptionsMenu(true) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.kt index 9f93d6006e5..e0d1e3250ae 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.kt @@ -44,7 +44,7 @@ class IndividualCollectionSheetFragment : MifosBaseFragment() { } private fun setupViewPager(viewPager: ViewPager?) { - val adapter = ViewPagerAdapter(activity!!.supportFragmentManager) + val adapter = ViewPagerAdapter(requireActivity().supportFragmentManager) adapter.addFragment(NewIndividualCollectionSheetFragment(), Constants.NEW) adapter.addFragment(SavedIndividualCollectionSheetFragment(), Constants.SAVED) viewPager!!.adapter = adapter diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/NewIndividualCollectionSheetFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/NewIndividualCollectionSheetFragment.kt index 5de25f34c78..27015d2f366 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/NewIndividualCollectionSheetFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/NewIndividualCollectionSheetFragment.kt @@ -101,14 +101,14 @@ class NewIndividualCollectionSheetFragment : MifosBaseFragment(), IndividualColl private fun setUpUi() { setRepaymentDate() officeNameList = ArrayList() - officeAdapter = ArrayAdapter(activity, - android.R.layout.simple_spinner_item, officeNameList) + officeAdapter = ArrayAdapter(requireActivity(), + android.R.layout.simple_spinner_item, officeNameList ?: emptyList()) officeAdapter!!.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spOffices!!.adapter = officeAdapter spOffices!!.onItemSelectedListener = this staffNameList = ArrayList() - staffAdapter = ArrayAdapter(activity, - android.R.layout.simple_spinner_item, staffNameList) + staffAdapter = ArrayAdapter(requireActivity(), + android.R.layout.simple_spinner_item, staffNameList ?: emptyList()) staffAdapter!!.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spStaff!!.adapter = staffAdapter tvRepaymentDate!!.setOnClickListener(this) @@ -187,7 +187,7 @@ class NewIndividualCollectionSheetFragment : MifosBaseFragment(), IndividualColl } fun setTvRepaymentDate() { - datePicker!!.show(activity!!.supportFragmentManager, + datePicker!!.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } @@ -221,7 +221,7 @@ class NewIndividualCollectionSheetFragment : MifosBaseFragment(), IndividualColl val collectionSheetDialogFragment = CollectionSheetDialogFragment.newInstance(tvRepaymentDate!!.text.toString(), sheet!!.clients.size) collectionSheetDialogFragment.setTargetFragment(this, requestCode) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_DOCUMENT_LIST) collectionSheetDialogFragment.show(fragmentTransaction, "Identifier Dialog Fragment") diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/IndividualCollectionSheetDetailsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/IndividualCollectionSheetDetailsFragment.kt index f4e776e5028..98d9e4cef62 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/IndividualCollectionSheetDetailsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/IndividualCollectionSheetDetailsFragment.kt @@ -50,9 +50,9 @@ class IndividualCollectionSheetDetailsFragment : MifosBaseFragment(), Individual sheet = savedInstanceState[Constants.EXTRA_COLLECTION_INDIVIDUAL] as IndividualCollectionSheet showCollectionSheetViews(sheet) } - sheet = arguments!!.getParcelable(Constants.INDIVIDUAL_SHEET) - actualDisbursementDate = arguments!!.getString(Constants.DISBURSEMENT_DATE) - transactionDate = arguments!!.getString(Constants.TRANSACTION_DATE) + sheet = requireArguments().getParcelable(Constants.INDIVIDUAL_SHEET) + actualDisbursementDate = requireArguments().getString(Constants.DISBURSEMENT_DATE) + transactionDate = requireArguments().getString(Constants.TRANSACTION_DATE) setHasOptionsMenu(true) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/PaymentDetailsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/PaymentDetailsFragment.kt index 7d7179f7caa..af1a47e7cc4 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/PaymentDetailsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/PaymentDetailsFragment.kt @@ -109,12 +109,12 @@ class PaymentDetailsFragment : MifosBaseFragment(), View.OnClickListener, OnItem override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) - position = arguments!!.getInt(Constants.ADAPTER_POSITION) - loanAndClientNameItem = arguments!!.getParcelable(Constants.LOAN_AND_CLIENT) - paymentTypeList = arguments!!.getStringArrayList(Constants.PAYMENT_LIST) - payload = arguments!!.getParcelable(Constants.PAYLOAD) - paymentTypeOptionsList = arguments!!.getParcelableArrayList(Constants.PAYMENT_OPTIONS) - clientId = arguments!!.getInt(Constants.CLIENT_ID) + position = requireArguments().getInt(Constants.ADAPTER_POSITION) + loanAndClientNameItem = requireArguments().getParcelable(Constants.LOAN_AND_CLIENT) + paymentTypeList = requireArguments().getStringArrayList(Constants.PAYMENT_LIST) + payload = requireArguments().getParcelable(Constants.PAYLOAD) + paymentTypeOptionsList = requireArguments().getParcelableArrayList(Constants.PAYMENT_OPTIONS) + clientId = requireArguments().getInt(Constants.CLIENT_ID) bulkRepaymentTransaction = BulkRepaymentTransactions() } @@ -155,8 +155,8 @@ class PaymentDetailsFragment : MifosBaseFragment(), View.OnClickListener, OnItem private fun showAdditional() { tableAdditional!!.visibility = View.VISIBLE - val adapter = ArrayAdapter(context, - android.R.layout.simple_spinner_item, paymentTypeList) + val adapter = ArrayAdapter(requireActivity(), + android.R.layout.simple_spinner_item, paymentTypeList ?: emptyList()) spPaymentOption!!.adapter = adapter spPaymentOption!!.setSelection(paymentTypeList!!.size - 1) spPaymentOption!!.onItemSelectedListener = this diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewcenter/CreateNewCenterFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewcenter/CreateNewCenterFragment.kt index ead7aa4c554..bb82721d2cc 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewcenter/CreateNewCenterFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewcenter/CreateNewCenterFragment.kt @@ -123,7 +123,7 @@ class CreateNewCenterFragment : MifosBaseFragment(), OnDatePickListener, CreateN fun inflateActivationDate() { newDatePicker = MFDatePicker.newInsance(this) tv_activationDate!!.text = MFDatePicker.getDatePickedAsString() - tv_activationDate!!.setOnClickListener { (newDatePicker as MFDatePicker?)!!.show(activity!!.supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } + tv_activationDate!!.setOnClickListener { (newDatePicker as MFDatePicker?)!!.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } } override fun onDatePicked(date: String) { @@ -168,7 +168,7 @@ class CreateNewCenterFragment : MifosBaseFragment(), OnDatePickListener, CreateN officeNameIdHashMap[office.name] = office.id } Collections.sort(officeList) - val officeAdapter = ArrayAdapter(activity, + val officeAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, officeList) officeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) sp_offices!!.adapter = officeAdapter @@ -191,7 +191,7 @@ class CreateNewCenterFragment : MifosBaseFragment(), OnDatePickListener, CreateN override fun centerCreatedSuccessfully(saveResponse: SaveResponse?) { Toast.makeText(activity, "Center " + MifosResponseHandler.getResponse(), Toast.LENGTH_LONG).show() - activity!!.supportFragmentManager.popBackStack() + requireActivity().supportFragmentManager.popBackStack() } override fun showFetchingError(errorMessage: Int) { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientFragment.kt index 1eefac03dc4..56b73ae267e 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewclient/CreateNewClientFragment.kt @@ -172,29 +172,29 @@ class CreateNewClientFragment : ProgressableFragment(), OnDatePickListener, Crea } override fun showUserInterface() { - genderOptionsAdapter = ArrayAdapter(activity, - android.R.layout.simple_spinner_item, genderOptionsList) + genderOptionsAdapter = ArrayAdapter(requireActivity(), + android.R.layout.simple_spinner_item, genderOptionsList ?: emptyList()) genderOptionsAdapter!!.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spGender!!.adapter = genderOptionsAdapter spGender!!.onItemSelectedListener = this - clientClassificationAdapter = ArrayAdapter(activity, - android.R.layout.simple_spinner_item, clientClassificationList) + clientClassificationAdapter = ArrayAdapter(requireActivity(), + android.R.layout.simple_spinner_item, clientClassificationList ?: emptyList()) clientClassificationAdapter!! .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spClientClassification!!.adapter = clientClassificationAdapter spClientClassification!!.onItemSelectedListener = this - clientTypeAdapter = ArrayAdapter(activity, - android.R.layout.simple_spinner_item, clientTypeList) + clientTypeAdapter = ArrayAdapter(requireActivity(), + android.R.layout.simple_spinner_item, clientTypeList ?: emptyList()) clientTypeAdapter!!.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spClientType!!.adapter = clientTypeAdapter spClientType!!.onItemSelectedListener = this - officeAdapter = ArrayAdapter(activity, - android.R.layout.simple_spinner_item, officeList) + officeAdapter = ArrayAdapter(requireActivity(), + android.R.layout.simple_spinner_item, officeList ?: emptyList()) officeAdapter!!.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spOffices!!.adapter = officeAdapter spOffices!!.onItemSelectedListener = this - staffAdapter = ArrayAdapter(activity, - android.R.layout.simple_spinner_item, staffList) + staffAdapter = ArrayAdapter(requireActivity(), + android.R.layout.simple_spinner_item, staffList ?: emptyList()) staffAdapter!!.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spStaff!!.adapter = staffAdapter spStaff!!.onItemSelectedListener = this @@ -203,7 +203,7 @@ class CreateNewClientFragment : ProgressableFragment(), OnDatePickListener, Crea tvSubmissionDate!!.text = MFDatePicker.getDatePickedAsString() tvDateOfBirth!!.text = MFDatePicker.getDatePickedAsString() ivClientImage!!.setOnClickListener { view -> - val menu = PopupMenu(activity!!, view) + val menu = PopupMenu(requireActivity(), view) menu.menuInflater.inflate(R.menu.menu_create_client_image, menu .menu) menu.setOnMenuItemClickListener { menuItem -> @@ -224,7 +224,7 @@ class CreateNewClientFragment : ProgressableFragment(), OnDatePickListener, Crea private fun captureClientImage() { val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE) ClientImageFile = File( - activity!!.externalCacheDir, "client_image.png") + requireActivity().externalCacheDir, "client_image.png") intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(ClientImageFile)) startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) } @@ -244,14 +244,14 @@ class CreateNewClientFragment : ProgressableFragment(), OnDatePickListener, Crea @OnClick(R.id.tv_submission_date) fun onClickTextViewSubmissionDate() { - datePickerSubmissionDate!!.show(activity!!.supportFragmentManager, + datePickerSubmissionDate!!.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) mCurrentDateView = tvSubmissionDate } @OnClick(R.id.tv_dateofbirth) fun onClickTextViewDateOfBirth() { - datePickerDateOfBirth!!.show(activity!!.supportFragmentManager, + datePickerDateOfBirth!!.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) mCurrentDateView = tvDateOfBirth } @@ -311,9 +311,9 @@ class CreateNewClientFragment : ProgressableFragment(), OnDatePickListener, Crea val fragment = DataTableListFragment.newInstance( clientsTemplate!!.dataTables, clientPayload, Constants.CREATE_CLIENT) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() - activity!!.supportFragmentManager.popBackStackImmediate() + requireActivity().supportFragmentManager.popBackStackImmediate() fragmentTransaction.addToBackStack(FragmentConstants.DATA_TABLE_LIST) fragmentTransaction.replace(R.id.container, fragment).commit() } else { @@ -379,7 +379,7 @@ class CreateNewClientFragment : ProgressableFragment(), OnDatePickListener, Crea override fun showWaitingForCheckerApproval(message: Int) { Toaster.show(rootView, message) - activity!!.supportFragmentManager.popBackStack() + requireActivity().supportFragmentManager.popBackStack() } override fun showMessage(message: Int) { @@ -483,7 +483,7 @@ class CreateNewClientFragment : ProgressableFragment(), OnDatePickListener, Crea if (createClientWithImage) { ClientImageFile?.let { createNewClientPresenter!!.uploadImage(returnedClientId!!, it) } } else { - activity!!.supportFragmentManager.popBackStack() + requireActivity().supportFragmentManager.popBackStack() } } @@ -493,12 +493,12 @@ class CreateNewClientFragment : ProgressableFragment(), OnDatePickListener, Crea createClientWithImage = true ivClientImage!!.setImageBitmap(BitmapFactory.decodeFile(ClientImageFile!!.absolutePath)) } else if (requestCode == PICK_IMAGE_ACTIVITY_REQUEST_CODE - && resultCode == Activity.RESULT_OK) { + && resultCode == Activity.RESULT_OK && data?.data != null) { createClientWithImage = true - pickedImageUri = data?.data + pickedImageUri = data.data val filePath = arrayOf(MediaStore.Images.Media.DATA) - val c = activity!!.contentResolver.query(pickedImageUri, filePath, - null, null, null) + val c = requireActivity().contentResolver.query(pickedImageUri!!, filePath, + null, null, null)!! c.moveToFirst() val columnIndex = c.getColumnIndex(filePath[0]) val picturePath = c.getString(columnIndex) @@ -523,7 +523,7 @@ class CreateNewClientFragment : ProgressableFragment(), OnDatePickListener, Crea //permission is automatically granted on sdk<23 upon installation val isStoragePermissionGranted: Boolean get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (activity!!.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) + if (requireActivity().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { true } else { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupFragment.kt index 4886c65fba0..b364c80a0e9 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/createnewgroup/CreateNewGroupFragment.kt @@ -146,7 +146,7 @@ class CreateNewGroupFragment : ProgressableFragment(), OnDatePickListener, Creat } private fun inflateOfficesSpinner() { - mOfficesAdapter = ArrayAdapter(activity, android.R.layout.simple_spinner_item, + mOfficesAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, mListOffices) mOfficesAdapter!!.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) sp_offices!!.adapter = mOfficesAdapter @@ -156,13 +156,13 @@ class CreateNewGroupFragment : ProgressableFragment(), OnDatePickListener, Creat fun inflateSubmissionDate() { mfDatePicker = MFDatePicker.newInsance(this) tv_submissionDate!!.text = MFDatePicker.getDatePickedAsString() - tv_submissionDate!!.setOnClickListener { (mfDatePicker as MFDatePicker?)?.show(activity!!.supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } + tv_submissionDate!!.setOnClickListener { (mfDatePicker as MFDatePicker?)?.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } } fun inflateActivationDate() { newDatePicker = MFDatePicker.newInsance(this) tv_activationDate!!.text = MFDatePicker.getDatePickedAsString() - tv_activationDate!!.setOnClickListener { (newDatePicker as MFDatePicker?)?.show(activity!!.supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } + tv_activationDate!!.setOnClickListener { (newDatePicker as MFDatePicker?)?.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } } override fun onDatePicked(date: String) { @@ -214,7 +214,7 @@ class CreateNewGroupFragment : ProgressableFragment(), OnDatePickListener, Creat override fun showGroupCreatedSuccessfully(group: SaveResponse?) { Toast.makeText(activity, "Group " + MifosResponseHandler.getResponse(), Toast.LENGTH_LONG).show() - activity!!.supportFragmentManager.popBackStack() + requireActivity().supportFragmentManager.popBackStack() if (PrefManager.getUserStatus() == Constants.USER_ONLINE) { val groupActivityIntent = Intent(activity, GroupsActivity::class.java) groupActivityIntent.putExtra(Constants.GROUP_ID, group?.groupId) diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableFragment.kt index 63a06f23224..0019b772ece 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableFragment.kt @@ -18,7 +18,6 @@ import com.mifos.mifosxdroid.R import com.mifos.mifosxdroid.adapters.DataTableAdapter import com.mifos.mifosxdroid.core.MifosBaseActivity import com.mifos.mifosxdroid.core.MifosBaseFragment -import com.mifos.mifosxdroid.core.RecyclerItemClickListener import com.mifos.mifosxdroid.core.util.Toaster import com.mifos.mifosxdroid.online.datatabledata.DataTableDataFragment import com.mifos.objects.noncore.DataTable @@ -30,7 +29,7 @@ import javax.inject.Inject /** * Created by Rajan Maurya on 12/02/17. */ -class DataTableFragment : MifosBaseFragment(), DataTableMvpView, OnRefreshListener, RecyclerItemClickListener.OnItemClickListener { +class DataTableFragment : MifosBaseFragment(), DataTableMvpView, OnRefreshListener { @JvmField @BindView(R.id.rv_data_table) var rvDataTable: RecyclerView? = null @@ -59,28 +58,28 @@ class DataTableFragment : MifosBaseFragment(), DataTableMvpView, OnRefreshListen @Inject var dataTablePresenter: DataTablePresenter? = null - @JvmField - @Inject - var dataTableAdapter: DataTableAdapter? = null + val dataTableAdapter by lazy { + DataTableAdapter( + onDateTableClick = { dataTable -> + val dataTableDataFragment: DataTableDataFragment = DataTableDataFragment.Companion.newInstance(dataTable, entityId) + val fragmentTransaction = requireActivity().supportFragmentManager + .beginTransaction() + fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CLIENT_DETAILS) + fragmentTransaction.replace(R.id.container, dataTableDataFragment, FragmentConstants.FRAG_DATA_TABLE) + fragmentTransaction.commit() + } + ) + } lateinit var rootView: View private var tableName: String? = null private var entityId = 0 private var dataTables: List? = null - override fun onItemClick(childView: View, position: Int) { - val dataTableDataFragment: DataTableDataFragment = DataTableDataFragment.Companion.newInstance(dataTables!![position], entityId) - val fragmentTransaction = activity!!.supportFragmentManager - .beginTransaction() - fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CLIENT_DETAILS) - fragmentTransaction.replace(R.id.container, dataTableDataFragment, FragmentConstants.FRAG_DATA_TABLE) - fragmentTransaction.commit() - } - override fun onItemLongPress(childView: View, position: Int) {} override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) if (arguments != null) { - tableName = arguments!!.getString(Constants.DATA_TABLE_NAME) - entityId = arguments!!.getInt(Constants.ENTITY_ID) + tableName = requireArguments().getString(Constants.DATA_TABLE_NAME) + entityId = requireArguments().getInt(Constants.ENTITY_ID) } dataTables = ArrayList() } @@ -106,7 +105,6 @@ class DataTableFragment : MifosBaseFragment(), DataTableMvpView, OnRefreshListen rvDataTable!!.layoutManager = mLayoutManager rvDataTable!!.setHasFixedSize(true) rvDataTable!!.adapter = dataTableAdapter - rvDataTable!!.addOnItemTouchListener(RecyclerItemClickListener(activity, this)) swipeRefreshLayout!!.setColorSchemeColors(*activity ?.getResources()!!.getIntArray(R.array.swipeRefreshColors)) swipeRefreshLayout!!.setOnRefreshListener(this) @@ -114,7 +112,7 @@ class DataTableFragment : MifosBaseFragment(), DataTableMvpView, OnRefreshListen override fun showDataTables(dataTables: List?) { this.dataTables = dataTables - dataTableAdapter!!.setDataTables(dataTables) + dataTableAdapter!!.dataTables = dataTables ?: emptyList() } override fun showEmptyDataTables() { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataFragment.kt index c0316143697..6b27c6bea2c 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatabledata/DataTableDataFragment.kt @@ -151,7 +151,7 @@ class DataTableDataFragment : MifosBaseFragment(), DataTableActionListener, Data val dataTableRowDialogFragment = DataTableRowDialogFragment .newInstance(dataTable, entityId) dataTableRowDialogFragment.setTargetFragment(this, Constants.DIALOG_FRAGMENT) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.DFRAG_DATATABLE_ENTRY_FORM) dataTableRowDialogFragment.show(fragmentTransaction, "Document Dialog Fragment") diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListFragment.kt index ec69b3a5021..1ffea56dd18 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListFragment.kt @@ -73,12 +73,12 @@ class DataTableListFragment : Fragment(), DataTableListMvpView { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - activity!!.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) + requireActivity().window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) rootView = inflater.inflate(R.layout.dialog_fragment_add_entry_to_datatable, container, false) ButterKnife.bind(this, rootView) mDataTableListPresenter!!.attachView(this) - activity!!.title = activity!!.resources.getString( + requireActivity().title = requireActivity().resources.getString( R.string.associated_datatables) safeUIBlockingUtility = SafeUIBlockingUtility(this@DataTableListFragment .activity, getString(R.string.create_client_loading_message)) @@ -90,13 +90,13 @@ class DataTableListFragment : Fragment(), DataTableListMvpView { } fun createForm(table: DataTable) { - val tableName = TextView(activity!!.applicationContext) + val tableName = TextView(requireActivity().applicationContext) tableName.text = table.registeredTableName tableName.gravity = Gravity.CENTER_HORIZONTAL tableName.setTypeface(null, Typeface.BOLD) - tableName.setTextColor(activity!!.resources.getColor(R.color.black)) + tableName.setTextColor(requireActivity().resources.getColor(R.color.black)) tableName.setTextSize(TypedValue.COMPLEX_UNIT_SP, - activity!!.resources.getDimension(R.dimen.datatable_name_heading)) + requireActivity().resources.getDimension(R.dimen.datatable_name_heading)) linearLayout!!.addView(tableName) val formWidgets: MutableList = ArrayList() for (columnHeader in table.columnHeaderData) { @@ -133,7 +133,7 @@ class DataTableListFragment : Fragment(), DataTableListMvpView { } else if (columnHeader.columnDisplayType == FormWidget.SCHEMA_KEY_DATE) { val formEditText = FormEditText(activity, columnHeader .columnName) - formEditText.setIsDateField(true, activity!!.supportFragmentManager) + formEditText.setIsDateField(true, requireActivity().supportFragmentManager) formWidgets.add(formEditText) linearLayout!!.addView(formEditText.view) } else if (columnHeader.columnDisplayType == FormWidget.SCHEMA_KEY_BOOL) { @@ -151,13 +151,13 @@ class DataTableListFragment : Fragment(), DataTableListMvpView { val bt_processForm = Button(activity) bt_processForm.layoutParams = FormWidget.defaultLayoutParams bt_processForm.text = getString(R.string.save) - bt_processForm.setBackgroundColor(activity!!.resources.getColor(R.color.blue_dark)) + bt_processForm.setBackgroundColor(requireActivity().resources.getColor(R.color.blue_dark)) linearLayout!!.addView(bt_processForm) bt_processForm.setOnClickListener { try { onSaveActionRequested() } catch (e: RequiredFieldException) { - Log.d(LOG_TAG, e.message) + Log.d(LOG_TAG, e.message.toString()) } } } @@ -208,17 +208,17 @@ class DataTableListFragment : Fragment(), DataTableListMvpView { override fun showMessage(messageId: Int) { Toaster.show(rootView, getString(messageId)) - activity!!.supportFragmentManager.popBackStackImmediate() + requireActivity().supportFragmentManager.popBackStackImmediate() } override fun showMessage(message: String?) { Toaster.show(rootView, message) - activity!!.supportFragmentManager.popBackStackImmediate() + requireActivity().supportFragmentManager.popBackStackImmediate() } override fun showClientCreatedSuccessfully(client: Client) { - activity!!.supportFragmentManager.popBackStack() - activity!!.supportFragmentManager.popBackStack() + requireActivity().supportFragmentManager.popBackStack() + requireActivity().supportFragmentManager.popBackStack() Toast.makeText(activity, getString(R.string.client) + MifosResponseHandler.getResponse(), Toast.LENGTH_SHORT).show() if (PrefManager.getUserStatus() == Constants.USER_ONLINE) { @@ -229,7 +229,7 @@ class DataTableListFragment : Fragment(), DataTableListMvpView { } override fun showWaitingForCheckerApproval(message: Int) { - activity!!.supportFragmentManager.popBackStack() + requireActivity().supportFragmentManager.popBackStack() Toaster.show(rootView, message, Toast.LENGTH_SHORT) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/documentlist/DocumentListFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/documentlist/DocumentListFragment.kt index 89af49e1fae..0aa48599dcf 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/documentlist/DocumentListFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/documentlist/DocumentListFragment.kt @@ -27,7 +27,6 @@ import com.mifos.mifosxdroid.adapters.DocumentListAdapter import com.mifos.mifosxdroid.core.MaterialDialog import com.mifos.mifosxdroid.core.MifosBaseActivity import com.mifos.mifosxdroid.core.MifosBaseFragment -import com.mifos.mifosxdroid.core.RecyclerItemClickListener import com.mifos.mifosxdroid.core.util.Toaster import com.mifos.mifosxdroid.dialogfragments.documentdialog.DocumentDialogFragment import com.mifos.objects.noncore.Document @@ -37,10 +36,9 @@ import com.mifos.utils.FileUtils import com.mifos.utils.FragmentConstants import okhttp3.ResponseBody import java.io.File -import java.util.* import javax.inject.Inject -class DocumentListFragment : MifosBaseFragment(), DocumentListMvpView, RecyclerItemClickListener.OnItemClickListener, OnRefreshListener { +class DocumentListFragment : MifosBaseFragment(), DocumentListMvpView, OnRefreshListener { @JvmField @BindView(R.id.rv_documents) var rv_documents: RecyclerView? = null @@ -65,28 +63,28 @@ class DocumentListFragment : MifosBaseFragment(), DocumentListMvpView, RecyclerI @Inject var mDocumentListPresenter: DocumentListPresenter? = null - @JvmField - @Inject - var mDocumentListAdapter: DocumentListAdapter? = null + private val mDocumentListAdapter by lazy { + DocumentListAdapter( + onDocumentClick = { documentSelected -> + document = documentSelected + showDocumentActions(documentSelected.id) + } + ) + } private lateinit var rootView: View private var entityType: String? = null private var entityId = 0 private var document: Document? = null private var documentBody: ResponseBody? = null private var mDocumentList: List? = null - override fun onItemClick(childView: View, position: Int) { - document = mDocumentList!![position] - showDocumentActions(mDocumentList!![position].id) - } - override fun onItemLongPress(childView: View, position: Int) {} override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) mDocumentList = ArrayList() if (arguments != null) { - entityType = arguments!!.getString(Constants.ENTITY_TYPE) - entityId = arguments!!.getInt(Constants.ENTITY_ID) + entityType = requireArguments().getString(Constants.ENTITY_TYPE) + entityId = requireArguments().getInt(Constants.ENTITY_ID) } setHasOptionsMenu(true) } @@ -100,7 +98,6 @@ class DocumentListFragment : MifosBaseFragment(), DocumentListMvpView, RecyclerI val layoutManager = LinearLayoutManager(activity) layoutManager.orientation = LinearLayoutManager.VERTICAL rv_documents!!.layoutManager = layoutManager - rv_documents!!.addOnItemTouchListener(RecyclerItemClickListener(activity, this)) rv_documents!!.setHasFixedSize(true) rv_documents!!.adapter = mDocumentListAdapter swipeRefreshLayout!!.setColorSchemeColors(*activity @@ -181,8 +178,7 @@ class DocumentListFragment : MifosBaseFragment(), DocumentListMvpView, RecyclerI override fun showDocumentList(documents: List) { mDocumentList = documents - mDocumentListAdapter!!.setDocuments(mDocumentList) - mDocumentListAdapter!!.notifyDataSetChanged() + mDocumentListAdapter!!.documents = documents if (documents.isEmpty()) { showEmptyDocuments() } else { @@ -240,7 +236,7 @@ class DocumentListFragment : MifosBaseFragment(), DocumentListMvpView, RecyclerI override fun showDocumentDialog(documentAction: String?) { val documentDialogFragment = DocumentDialogFragment.newInstance(entityType, entityId, documentAction, document) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_DOCUMENT_LIST) documentDialogFragment.show(fragmentTransaction, "Document Dialog Fragment") @@ -283,7 +279,7 @@ class DocumentListFragment : MifosBaseFragment(), DocumentListMvpView, RecyclerI menu.clear() val menuItemAddNewDocument = menu.add(Menu.NONE, MENU_ITEM_ADD_NEW_DOCUMENT, Menu.NONE, getString(R.string.add_new)) menuItemAddNewDocument.icon = ContextCompat - .getDrawable(activity!!, R.drawable.ic_add_white_24dp) + .getDrawable(requireActivity(), R.drawable.ic_add_white_24dp) menuItemAddNewDocument.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM) super.onPrepareOptionsMenu(menu) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/generatecollectionsheet/GenerateCollectionSheetFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/generatecollectionsheet/GenerateCollectionSheetFragment.kt index 8673c9432b2..c0f08efef92 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/generatecollectionsheet/GenerateCollectionSheetFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/generatecollectionsheet/GenerateCollectionSheetFragment.kt @@ -119,7 +119,7 @@ class GenerateCollectionSheetFragment : MifosBaseFragment(), GenerateCollectionS } override fun onOptionsItemSelected(item: MenuItem): Boolean { - if (item.itemId == R.id.mItem_search) activity!!.finish() + if (item.itemId == R.id.mItem_search) requireActivity().finish() return super.onOptionsItemSelected(item) } @@ -696,7 +696,7 @@ class GenerateCollectionSheetFragment : MifosBaseFragment(), GenerateCollectionS } private fun setMeetingDate() { - datePicker!!.show(activity!!.supportFragmentManager, + datePicker!!.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } @@ -720,7 +720,7 @@ class GenerateCollectionSheetFragment : MifosBaseFragment(), GenerateCollectionS } private fun setSpinner(spinner: Spinner?, values: List) { - val adapter = ArrayAdapter(activity, + val adapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, values) adapter.notifyDataSetChanged() adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupdetails/GroupDetailsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupdetails/GroupDetailsFragment.kt index 0c5839c14d5..593c1c60e37 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupdetails/GroupDetailsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupdetails/GroupDetailsFragment.kt @@ -96,7 +96,7 @@ class GroupDetailsFragment : MifosBaseFragment(), GroupDetailsMvpView { super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) if (arguments != null) { - groupId = arguments!!.getInt(Constants.GROUP_ID) + groupId = requireArguments().getInt(Constants.GROUP_ID) } setHasOptionsMenu(true) } @@ -112,7 +112,7 @@ class GroupDetailsFragment : MifosBaseFragment(), GroupDetailsMvpView { @OnClick(R.id.btn_activate_group) fun onClickActivateGroup() { val activateFragment = ActivateFragment.newInstance(groupId, Constants.ACTIVATE_GROUP) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CLIENT_DETAILS) fragmentTransaction.replace(R.id.container, activateFragment) @@ -121,7 +121,7 @@ class GroupDetailsFragment : MifosBaseFragment(), GroupDetailsMvpView { fun loadDocuments() { val documentListFragment = DocumentListFragment.newInstance(Constants.ENTITY_TYPE_GROUPS, groupId) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_GROUP_DETAILS) fragmentTransaction.replace(R.id.container, documentListFragment) @@ -130,7 +130,7 @@ class GroupDetailsFragment : MifosBaseFragment(), GroupDetailsMvpView { fun loadNotes() { val noteFragment = NoteFragment.newInstance(Constants.ENTITY_TYPE_GROUPS, groupId) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CLIENT_DETAILS) fragmentTransaction.replace(R.id.container, noteFragment) @@ -139,7 +139,7 @@ class GroupDetailsFragment : MifosBaseFragment(), GroupDetailsMvpView { fun addGroupSavingsAccount() { val savingsAccountFragment = SavingsAccountFragment.newInstance(groupId, true) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_GROUP_DETAILS) fragmentTransaction.replace(R.id.container, savingsAccountFragment) @@ -148,7 +148,7 @@ class GroupDetailsFragment : MifosBaseFragment(), GroupDetailsMvpView { fun addGroupLoanAccount() { val grouploanAccountFragment = GroupLoanAccountFragment.newInstance(groupId) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_GROUP_DETAILS) fragmentTransaction.replace(R.id.container, grouploanAccountFragment) @@ -157,7 +157,7 @@ class GroupDetailsFragment : MifosBaseFragment(), GroupDetailsMvpView { fun loadGroupDataTables() { val dataTableFragment = DataTableFragment.newInstance(Constants.DATA_TABLE_NAME_GROUP, groupId) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_GROUP_DETAILS) fragmentTransaction.replace(R.id.container, dataTableFragment) @@ -212,13 +212,13 @@ class GroupDetailsFragment : MifosBaseFragment(), GroupDetailsMvpView { accountAccordion = AccountAccordion(activity) if (groupAccounts?.loanAccounts!!.size > 0) { val section = AccountAccordion.Section.LOANS - val adapter = LoanAccountsListAdapter(activity!!.applicationContext, + val adapter = LoanAccountsListAdapter(requireActivity().applicationContext, groupAccounts?.loanAccounts) section.connect(activity, adapter, AdapterView.OnItemClickListener { adapterView, view, i, l -> mListener!!.loadLoanAccountSummary(adapter.getItem(i).id) }) } if (groupAccounts.nonRecurringSavingsAccounts.size > 0) { val section = AccountAccordion.Section.SAVINGS - val adapter = SavingsAccountsListAdapter(activity!!.applicationContext, + val adapter = SavingsAccountsListAdapter(requireActivity().applicationContext, groupAccounts.nonRecurringSavingsAccounts) section.connect(activity, adapter, AdapterView.OnItemClickListener { adapterView, view, i, l -> mListener!!.loadSavingsAccountSummary(adapter.getItem(i).id, @@ -227,7 +227,7 @@ class GroupDetailsFragment : MifosBaseFragment(), GroupDetailsMvpView { } if (groupAccounts.recurringSavingsAccounts.size > 0) { val section = AccountAccordion.Section.RECURRING - val adapter = SavingsAccountsListAdapter(activity!!.applicationContext, + val adapter = SavingsAccountsListAdapter(requireActivity().applicationContext, groupAccounts.recurringSavingsAccounts) section.connect(activity, adapter, AdapterView.OnItemClickListener { adapterView, view, i, l -> mListener!!.loadSavingsAccountSummary(adapter.getItem(i).id, diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/grouplist/GroupListFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/grouplist/GroupListFragment.kt index c57229495cc..9bd29ae7a20 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/grouplist/GroupListFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/grouplist/GroupListFragment.kt @@ -55,7 +55,7 @@ class GroupListFragment : ProgressableFragment(), GroupListMvpView, AdapterView. override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) - if (arguments != null) centerId = arguments!!.getInt(Constants.CENTER_ID) + if (arguments != null) centerId = requireArguments().getInt(Constants.CENTER_ID) } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/grouploanaccount/GroupLoanAccountFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/grouploanaccount/GroupLoanAccountFragment.kt index f6330dd336c..2cfdce8256e 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/grouploanaccount/GroupLoanAccountFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/grouploanaccount/GroupLoanAccountFragment.kt @@ -200,13 +200,13 @@ class GroupLoanAccountFragment : ProgressableDialogFragment(), OnDatePickListene override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) - if (arguments != null) groupId = arguments!!.getInt(Constants.GROUP_ID) + if (arguments != null) groupId = requireArguments().getInt(Constants.GROUP_ID) } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { // Inflate the layout for this fragment - if (activity!!.actionBar != null) activity!!.actionBar.setDisplayHomeAsUpEnabled(true) + activity?.actionBar?.setDisplayHomeAsUpEnabled(true) rootView = inflater.inflate(R.layout.fragment_add_loan, null) ButterKnife.bind(this, rootView) mGroupLoanAccountPresenter!!.attachView(this) @@ -260,55 +260,55 @@ class GroupLoanAccountFragment : ProgressableDialogFragment(), OnDatePickListene } fun inflateLoanSpinner() { - amortizationTypeAdapter = ArrayAdapter(activity, + amortizationTypeAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, amortizationType) amortizationTypeAdapter!! .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spAmortization!!.adapter = amortizationTypeAdapter spAmortization!!.onItemSelectedListener = this - interestCalculationPeriodTypeAdapter = ArrayAdapter(activity, + interestCalculationPeriodTypeAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, interestCalculationPeriodType) interestCalculationPeriodTypeAdapter!! .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spInterestCalculationPeriod!!.adapter = interestCalculationPeriodTypeAdapter spInterestCalculationPeriod!!.onItemSelectedListener = this - transactionProcessingStrategyAdapter = ArrayAdapter(activity, + transactionProcessingStrategyAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, transactionProcessingStrategy) transactionProcessingStrategyAdapter!! .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spRepaymentStrategy!!.adapter = transactionProcessingStrategyAdapter spRepaymentStrategy!!.onItemSelectedListener = this - termFrequencyTypeAdapter = ArrayAdapter(activity, + termFrequencyTypeAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, termFrequencyType) termFrequencyTypeAdapter!! .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spPaymentPeriods!!.adapter = termFrequencyTypeAdapter spPaymentPeriods!!.onItemSelectedListener = this - loanProductAdapter = ArrayAdapter(activity, + loanProductAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, mListLoanProductsNames) loanProductAdapter!! .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spLoanProduct!!.adapter = loanProductAdapter spLoanProduct!!.onItemSelectedListener = this - loanPurposeTypeAdapter = ArrayAdapter(activity, + loanPurposeTypeAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, loanPurposeType) loanPurposeTypeAdapter!! .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spLoanPurpose!!.adapter = loanPurposeTypeAdapter spLoanPurpose!!.onItemSelectedListener = this - interestTypeOptionsAdapter = ArrayAdapter(activity, + interestTypeOptionsAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, interestTypeOptions) interestTypeOptionsAdapter!! .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spInterestType!!.adapter = interestTypeOptionsAdapter spInterestType!!.onItemSelectedListener = this - loanOfficerOptionsAdapter = ArrayAdapter(activity, + loanOfficerOptionsAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, loanOfficerOptions) loanOfficerOptionsAdapter!! .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spLoanOfficer!!.adapter = loanOfficerOptionsAdapter spLoanOfficer!!.onItemSelectedListener = this - fundOptionsAdapter = ArrayAdapter(activity, + fundOptionsAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, fundOptions) fundOptionsAdapter!! .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) @@ -318,14 +318,14 @@ class GroupLoanAccountFragment : ProgressableDialogFragment(), OnDatePickListene private fun inflateRepaidMonthSpinners() { mRepaymentFrequencyNthDayTypeOptionsAdapter = ArrayAdapter( - activity, android.R.layout.simple_spinner_item, + requireActivity(), android.R.layout.simple_spinner_item, mListRepaymentFrequencyNthDayTypeOptions) mRepaymentFrequencyNthDayTypeOptionsAdapter!! .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spRepaymentFreqNthDay!!.adapter = mRepaymentFrequencyNthDayTypeOptionsAdapter spRepaymentFreqNthDay!!.onItemSelectedListener = this mRepaymentFrequencyDayOfWeekTypeOptionsAdapter = ArrayAdapter( - activity, android.R.layout.simple_spinner_item, + requireActivity(), android.R.layout.simple_spinner_item, mListRepaymentFrequencyDayOfWeekTypeOptions) mRepaymentFrequencyDayOfWeekTypeOptionsAdapter!! .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) @@ -366,7 +366,7 @@ class GroupLoanAccountFragment : ProgressableDialogFragment(), OnDatePickListene @OnClick(R.id.tv_submittedon_date) fun onClickSubmittedonDate() { issubmittedDate = true - mfDatePicker!!.show(activity!!.supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) + mfDatePicker!!.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } fun inflateDisbursementDate() { @@ -377,7 +377,7 @@ class GroupLoanAccountFragment : ProgressableDialogFragment(), OnDatePickListene @OnClick(R.id.tv_disbursementon_date) fun onClickDisbursementonDate() { isdisbursementDate = true - mfDatePicker!!.show(activity!!.supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) + mfDatePicker!!.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } override fun showAllLoans(productLoans: List?) { @@ -432,7 +432,7 @@ class GroupLoanAccountFragment : ProgressableDialogFragment(), OnDatePickListene } override fun showGroupLoansAccountCreatedSuccessfully(loans: Loans?) { - Toast.makeText(activity, "The Loan has been submitted for Approval", Toast.LENGTH_LONG).show() + Toast.makeText(requireActivity(), "The Loan has been submitted for Approval", Toast.LENGTH_LONG).show() } override fun showFetchingError(s: String?) { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListFragment.kt index 8d41258609f..a693f5fb7be 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListFragment.kt @@ -10,7 +10,6 @@ import android.os.Parcelable import android.view.* import android.widget.ProgressBar import androidx.appcompat.view.ActionMode -import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import androidx.swiperefreshlayout.widget.SwipeRefreshLayout @@ -24,7 +23,6 @@ import com.mifos.mifosxdroid.adapters.GroupNameListAdapter import com.mifos.mifosxdroid.core.EndlessRecyclerViewScrollListener import com.mifos.mifosxdroid.core.MifosBaseActivity import com.mifos.mifosxdroid.core.MifosBaseFragment -import com.mifos.mifosxdroid.core.RecyclerItemClickListener import com.mifos.mifosxdroid.core.util.Toaster import com.mifos.mifosxdroid.dialogfragments.syncgroupsdialog.SyncGroupsDialogFragment import com.mifos.mifosxdroid.online.GroupsActivity @@ -60,7 +58,7 @@ import javax.inject.Inject * boolean isParentFragment) {...} * and unregister the ScrollListener and SwipeLayout. */ -class GroupsListFragment : MifosBaseFragment(), GroupsListMvpView, RecyclerItemClickListener.OnItemClickListener, OnRefreshListener { +class GroupsListFragment : MifosBaseFragment(), GroupsListMvpView, OnRefreshListener { @JvmField @BindView(R.id.rv_groups) var rv_groups: RecyclerView? = null @@ -81,9 +79,25 @@ class GroupsListFragment : MifosBaseFragment(), GroupsListMvpView, RecyclerItemC @Inject var mGroupsListPresenter: GroupsListPresenter? = null - @JvmField - @Inject - var mGroupListAdapter: GroupNameListAdapter? = null + val mGroupListAdapter by lazy { + GroupNameListAdapter( + onGroupClick = { position -> + if (actionMode != null) { + toggleSelection(position) + } else { + val groupActivityIntent = Intent(activity, GroupsActivity::class.java) + groupActivityIntent.putExtra(Constants.GROUP_ID, mGroupList!![position].id) + startActivity(groupActivityIntent) + } + }, + onGroupLongClick = { position -> + if (actionMode == null) { + actionMode = (activity as MifosBaseActivity?)!!.startSupportActionMode(actionModeCallback!!) + } + toggleSelection(position) + } + ) + } var mLayoutManager: LinearLayoutManager? = null private var mGroupList: List? = null private var selectedGroups: MutableList? = null @@ -92,22 +106,6 @@ class GroupsListFragment : MifosBaseFragment(), GroupsListMvpView, RecyclerItemC private var actionModeCallback: ActionModeCallback? = null private var actionMode: ActionMode? = null private var sweetUIErrorHandler: SweetUIErrorHandler? = null - override fun onItemClick(childView: View, position: Int) { - if (actionMode != null) { - toggleSelection(position) - } else { - val groupActivityIntent = Intent(activity, GroupsActivity::class.java) - groupActivityIntent.putExtra(Constants.GROUP_ID, mGroupList!![position].id) - startActivity(groupActivityIntent) - } - } - - override fun onItemLongPress(childView: View, position: Int) { - if (actionMode == null) { - actionMode = (activity as MifosBaseActivity?)!!.startSupportActionMode(actionModeCallback!!) - } - toggleSelection(position) - } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -117,7 +115,7 @@ class GroupsListFragment : MifosBaseFragment(), GroupsListMvpView, RecyclerItemC actionModeCallback = ActionModeCallback() if (arguments != null) { mGroupList = requireArguments().getParcelableArrayList(Constants.GROUPS) - isParentFragment = arguments!! + isParentFragment = requireArguments() .getBoolean(Constants.IS_A_PARENT_FRAGMENT) } setHasOptionsMenu(true) @@ -163,9 +161,7 @@ class GroupsListFragment : MifosBaseFragment(), GroupsListMvpView, RecyclerItemC mLayoutManager = LinearLayoutManager(activity) mLayoutManager!!.orientation = LinearLayoutManager.VERTICAL rv_groups!!.layoutManager = mLayoutManager - rv_groups!!.addOnItemTouchListener(RecyclerItemClickListener(activity, this)) rv_groups!!.setHasFixedSize(true) - mGroupListAdapter!!.setContext(activity) rv_groups!!.adapter = mGroupListAdapter swipeRefreshLayout!!.setColorSchemeColors(*activity ?.getResources()!!.getIntArray(R.array.swipeRefreshColors)) @@ -207,7 +203,7 @@ class GroupsListFragment : MifosBaseFragment(), GroupsListMvpView, RecyclerItemC override fun showGroups(groups: List?) { mGroupList = groups as List? Collections.sort(mGroupList) { grp1, grp2 -> grp1.name.compareTo(grp2.name) } - mGroupListAdapter!!.setGroups(groups) + mGroupListAdapter!!.setGroups(mGroupList ?: emptyList()) } /** diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccount/LoanAccountFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccount/LoanAccountFragment.kt index 5d0198a394c..81af756be07 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccount/LoanAccountFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccount/LoanAccountFragment.kt @@ -201,11 +201,11 @@ class LoanAccountFragment : ProgressableDialogFragment(), OnDatePickListener, Lo var mInterestTypeOptionsAdapter: ArrayAdapter? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - if (arguments != null) clientId = arguments!!.getInt(Constants.CLIENT_ID) + if (arguments != null) clientId = requireArguments().getInt(Constants.CLIENT_ID) } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - if (activity!!.actionBar != null) activity!!.actionBar.setDisplayHomeAsUpEnabled(true) + activity?.actionBar?.setDisplayHomeAsUpEnabled(true) rootView = inflater.inflate(R.layout.fragment_add_loan, null) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) ButterKnife.bind(this, rootView) @@ -259,7 +259,7 @@ class LoanAccountFragment : ProgressableDialogFragment(), OnDatePickListener, Lo val fragment = DataTableListFragment.newInstance( mLoanTemplate.dataTables, loansPayload, Constants.CLIENT_LOAN) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.DATA_TABLE_LIST) fragmentTransaction.replace(R.id.container, fragment).commit() @@ -284,28 +284,28 @@ class LoanAccountFragment : ProgressableDialogFragment(), OnDatePickListener, Lo private fun inflateSpinners() { //Inflating the LoanProducts Spinner - mLoanProductAdapter = ArrayAdapter(activity, android.R.layout.simple_spinner_item, + mLoanProductAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, mListLoanProducts) mLoanProductAdapter!!.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spLoanProduct!!.adapter = mLoanProductAdapter spLoanProduct!!.onItemSelectedListener = this //Inflating the LoanPurposeOptions - mLoanPurposeOptionsAdapter = ArrayAdapter(activity, android.R.layout.simple_spinner_item, + mLoanPurposeOptionsAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, mListLoanPurposeOptions) mLoanPurposeOptionsAdapter!!.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spLoanPurpose!!.adapter = mLoanPurposeOptionsAdapter spLoanPurpose!!.onItemSelectedListener = this //Inflating Linking Options - mAccountLinkingOptionsAdapter = ArrayAdapter(activity, + mAccountLinkingOptionsAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, mListAccountLinkingOptions) mAccountLinkingOptionsAdapter!!.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spLinkingOptions!!.adapter = mAccountLinkingOptionsAdapter spLinkingOptions!!.onItemSelectedListener = this //Inflating AmortizationTypeOptions Spinner - mAmortizationTypeOptionsAdapter = ArrayAdapter(activity, + mAmortizationTypeOptionsAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, mListAmortizationTypeOptions) mAmortizationTypeOptionsAdapter!!.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item) @@ -313,7 +313,7 @@ class LoanAccountFragment : ProgressableDialogFragment(), OnDatePickListener, Lo spAmortization!!.onItemSelectedListener = this //Inflating InterestCalculationPeriodTypeOptions Spinner - mInterestCalculationPeriodTypeOptionsAdapter = ArrayAdapter(activity, + mInterestCalculationPeriodTypeOptionsAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, mListInterestCalculationPeriodTypeOptions) mInterestCalculationPeriodTypeOptionsAdapter!!.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item) @@ -321,7 +321,7 @@ class LoanAccountFragment : ProgressableDialogFragment(), OnDatePickListener, Lo spInterestCalculationPeriod!!.onItemSelectedListener = this //Inflate TransactionProcessingStrategyOptions Spinner - mTransactionProcessingStrategyOptionsAdapter = ArrayAdapter(activity, + mTransactionProcessingStrategyOptionsAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, mListTransactionProcessingStrategyOptions) mTransactionProcessingStrategyOptionsAdapter!!.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item) @@ -329,7 +329,7 @@ class LoanAccountFragment : ProgressableDialogFragment(), OnDatePickListener, Lo spRepaymentStrategy!!.onItemSelectedListener = this //Inflate TermFrequencyTypeOptionsAdapter Spinner - mTermFrequencyTypeOptionsAdapter = ArrayAdapter(activity, + mTermFrequencyTypeOptionsAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, mListTermFrequencyTypeOptions) mTermFrequencyTypeOptionsAdapter!!.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item) @@ -337,7 +337,7 @@ class LoanAccountFragment : ProgressableDialogFragment(), OnDatePickListener, Lo spPaymentPeriods!!.onItemSelectedListener = this //Inflate LoanTerm Frequency Type adapter - mLoanTermFrequencyTypeAdapter = ArrayAdapter(activity, + mLoanTermFrequencyTypeAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, mListLoanTermFrequencyTypeOptions) mLoanTermFrequencyTypeAdapter!!.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item) @@ -345,21 +345,21 @@ class LoanAccountFragment : ProgressableDialogFragment(), OnDatePickListener, Lo spLoanTermFrequencyType!!.onItemSelectedListener = this //Inflate FondOptions Spinner - mLoanFundOptionsAdapter = ArrayAdapter(activity, + mLoanFundOptionsAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, mListLoanFundOptions) mLoanFundOptionsAdapter!!.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spFund!!.adapter = mLoanFundOptionsAdapter spFund!!.onItemSelectedListener = this //Inflating LoanOfficerOptions Spinner - mLoanOfficerOptionsAdapter = ArrayAdapter(activity, + mLoanOfficerOptionsAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, mListLoanOfficerOptions) mLoanOfficerOptionsAdapter!!.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spLoanOfficer!!.adapter = mLoanOfficerOptionsAdapter spLoanOfficer!!.onItemSelectedListener = this //Inflating InterestTypeOptions Spinner - mInterestTypeOptionsAdapter = ArrayAdapter(activity, + mInterestTypeOptionsAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, mListInterestTypeOptions) mInterestTypeOptionsAdapter!!.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spInterestType!!.adapter = mInterestTypeOptionsAdapter @@ -368,14 +368,14 @@ class LoanAccountFragment : ProgressableDialogFragment(), OnDatePickListener, Lo private fun inflateRepaidMonthSpinners() { mRepaymentFrequencyNthDayTypeOptionsAdapter = ArrayAdapter( - activity, android.R.layout.simple_spinner_item, + requireActivity(), android.R.layout.simple_spinner_item, mListRepaymentFrequencyNthDayTypeOptions) mRepaymentFrequencyNthDayTypeOptionsAdapter!! .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spRepaymentFreqNthDay!!.adapter = mRepaymentFrequencyNthDayTypeOptionsAdapter spRepaymentFreqNthDay!!.onItemSelectedListener = this mRepaymentFrequencyDayOfWeekTypeOptionsAdapter = ArrayAdapter( - activity, android.R.layout.simple_spinner_item, + requireActivity(), android.R.layout.simple_spinner_item, mListRepaymentFrequencyDayOfWeekTypeOptions) mRepaymentFrequencyDayOfWeekTypeOptionsAdapter!! .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) @@ -406,7 +406,7 @@ class LoanAccountFragment : ProgressableDialogFragment(), OnDatePickListener, Lo @OnClick(R.id.tv_submittedon_date) fun setTvSubmittedOnDate() { isSubmissionDate = true - mfDatePicker!!.show(activity!!.supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) + mfDatePicker!!.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } fun inflateDisbursementDate() { @@ -417,7 +417,7 @@ class LoanAccountFragment : ProgressableDialogFragment(), OnDatePickListener, Lo @OnClick(R.id.tv_disbursementon_date) fun setTvDisbursementOnDate() { isDisbursebemntDate = true - mfDatePicker!!.show(activity!!.supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) + mfDatePicker!!.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } override fun showAllLoan(loans: List) { @@ -507,7 +507,7 @@ class LoanAccountFragment : ProgressableDialogFragment(), OnDatePickListener, Lo override fun showLoanAccountCreatedSuccessfully(loans: Loans?) { Toast.makeText(activity, R.string.loan_creation_success, Toast.LENGTH_LONG).show() - activity!!.supportFragmentManager.popBackStackImmediate() + requireActivity().supportFragmentManager.popBackStackImmediate() } override fun showMessage(messageId: Int) { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountapproval/LoanAccountApproval.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountapproval/LoanAccountApproval.kt index 9d0bf1724e8..ffa4670ecd2 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountapproval/LoanAccountApproval.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountapproval/LoanAccountApproval.kt @@ -75,8 +75,8 @@ class LoanAccountApproval : MifosBaseFragment(), OnDatePickListener, LoanAccount super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) if (arguments != null) { - loanAccountNumber = arguments!!.getInt(Constants.LOAN_ACCOUNT_NUMBER) - loanWithAssociations = arguments!!.getParcelable(Constants.LOAN_SUMMARY) + loanAccountNumber = requireArguments().getInt(Constants.LOAN_ACCOUNT_NUMBER) + loanWithAssociations = requireArguments().getParcelable(Constants.LOAN_SUMMARY) } setHasOptionsMenu(true) } @@ -84,7 +84,7 @@ class LoanAccountApproval : MifosBaseFragment(), OnDatePickListener, LoanAccount override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { // Inflate the layout for this fragment - if (activity!!.actionBar != null) activity!!.actionBar.setDisplayHomeAsUpEnabled(true) + activity?.actionBar?.setDisplayHomeAsUpEnabled(true) rootView = inflater.inflate(R.layout.dialog_fragment_approve_loan, null) ButterKnife.bind(this, rootView) mLoanAccountApprovalPresenter!!.attachView(this) @@ -111,13 +111,13 @@ class LoanAccountApproval : MifosBaseFragment(), OnDatePickListener, LoanAccount @OnClick(R.id.tv_loan_approval_dates) fun setApprovalDate() { isApprovalDate = true - mfDatePicker!!.show(activity!!.supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) + mfDatePicker!!.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } @OnClick(R.id.tv_expected_disbursement_dates) fun setDisbursementDate() { isDisbursebemntDate = true - mfDatePicker!!.show(activity!!.supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) + mfDatePicker!!.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } fun showApprovalDate() { @@ -162,7 +162,7 @@ class LoanAccountApproval : MifosBaseFragment(), OnDatePickListener, LoanAccount override fun showLoanApproveSuccessfully(genericResponse: GenericResponse?) { Toast.makeText(activity, "Loan Approved", Toast.LENGTH_LONG).show() - activity!!.supportFragmentManager.popBackStackImmediate() + requireActivity().supportFragmentManager.popBackStackImmediate() } override fun showLoanApproveFailed(s: String?) { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountdisbursement/LoanAccountDisbursementFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountdisbursement/LoanAccountDisbursementFragment.kt index 0897ee7868b..9f59c0df6cd 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountdisbursement/LoanAccountDisbursementFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountdisbursement/LoanAccountDisbursementFragment.kt @@ -73,14 +73,14 @@ class LoanAccountDisbursementFragment : MifosBaseFragment(), OnDatePickListener, super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) if (arguments != null) { - loanAccountNumber = arguments!!.getInt(Constants.LOAN_ACCOUNT_NUMBER) + loanAccountNumber = requireArguments().getInt(Constants.LOAN_ACCOUNT_NUMBER) } paymentTypeOptions = ArrayList() setHasOptionsMenu(true) } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - if (activity!!.actionBar != null) activity!!.actionBar.setDisplayHomeAsUpEnabled(true) + activity?.actionBar?.setDisplayHomeAsUpEnabled(true) rootView = inflater.inflate(R.layout.dialog_fragment_disburse_loan, null) ButterKnife.bind(this, rootView) loanAccountDisbursementPresenter!!.attachView(this) @@ -113,8 +113,8 @@ class LoanAccountDisbursementFragment : MifosBaseFragment(), OnDatePickListener, mfDatePicker = MFDatePicker.newInsance(this) tvLoanDisbursementDates!!.text = MFDatePicker.getDatePickedAsString() showDisbursementDate(tvLoanDisbursementDates!!.text.toString()) - paymentTypeOptionAdapter = ArrayAdapter(activity, - android.R.layout.simple_spinner_item, paymentTypeOptions) + paymentTypeOptionAdapter = ArrayAdapter(requireActivity(), + android.R.layout.simple_spinner_item, paymentTypeOptions ?: emptyList()) paymentTypeOptionAdapter!! .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spPaymentType!!.adapter = paymentTypeOptionAdapter @@ -128,7 +128,7 @@ class LoanAccountDisbursementFragment : MifosBaseFragment(), OnDatePickListener, @OnClick(R.id.tv_loan_disbursement_dates) fun onClickTvDisburseDate() { - mfDatePicker!!.show(activity!!.supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) + mfDatePicker!!.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } override fun onDatePicked(date: String) { @@ -146,7 +146,7 @@ class LoanAccountDisbursementFragment : MifosBaseFragment(), OnDatePickListener, override fun showDisburseLoanSuccessfully(genericResponse: GenericResponse?) { Toast.makeText(activity, R.string.loan_disburse_successfully, Toast.LENGTH_LONG).show() - activity!!.supportFragmentManager.popBackStack() + requireActivity().supportFragmentManager.popBackStack() } override fun showError(message: String?) { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountsummary/LoanAccountSummaryFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountsummary/LoanAccountSummaryFragment.kt index c95cd16696a..df562b6709c 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountsummary/LoanAccountSummaryFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanaccountsummary/LoanAccountSummaryFragment.kt @@ -152,8 +152,8 @@ class LoanAccountSummaryFragment : ProgressableFragment(), LoanAccountSummaryMvp override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) if (arguments != null) { - loanAccountNumber = arguments!!.getInt(Constants.LOAN_ACCOUNT_NUMBER) - parentFragment = arguments!!.getBoolean(Constants.IS_A_PARENT_FRAGMENT) + loanAccountNumber = requireArguments().getInt(Constants.LOAN_ACCOUNT_NUMBER) + parentFragment = requireArguments().getBoolean(Constants.IS_A_PARENT_FRAGMENT) } //Necessary Call to add and update the Menu in a Fragment setHasOptionsMenu(true) @@ -187,7 +187,7 @@ class LoanAccountSummaryFragment : ProgressableFragment(), LoanAccountSummaryMvp } else if (processLoanTransactionAction == ACTION_DISBURSE_LOAN) { disburseLoan() } else { - Log.i(activity!!.localClassName, "TRANSACTION ACTION NOT SET") + Log.i(requireActivity().localClassName, "TRANSACTION ACTION NOT SET") } } @@ -204,7 +204,7 @@ class LoanAccountSummaryFragment : ProgressableFragment(), LoanAccountSummaryMvp override fun onDetach() { super.onDetach() if (!parentFragment) { - activity!!.finish() + requireActivity().finish() } } @@ -272,7 +272,7 @@ class LoanAccountSummaryFragment : ProgressableFragment(), LoanAccountSummaryMvp fun loadDocuments() { val documentListFragment = DocumentListFragment.newInstance(Constants.ENTITY_TYPE_LOANS, loanAccountNumber) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_LOAN_ACCOUNT_SUMMARY) fragmentTransaction.replace(R.id.container, documentListFragment) @@ -282,7 +282,7 @@ class LoanAccountSummaryFragment : ProgressableFragment(), LoanAccountSummaryMvp fun loadloanCharges() { val loanChargeFragment: LoanChargeFragment = LoanChargeFragment.Companion.newInstance(loanAccountNumber, chargesList) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_LOAN_ACCOUNT_SUMMARY) fragmentTransaction.replace(R.id.container, loanChargeFragment) @@ -291,7 +291,7 @@ class LoanAccountSummaryFragment : ProgressableFragment(), LoanAccountSummaryMvp fun approveLoan() { val loanAccountApproval: LoanAccountApproval = LoanAccountApproval.Companion.newInstance(loanAccountNumber, clientLoanWithAssociations) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_LOAN_ACCOUNT_SUMMARY) fragmentTransaction.replace(R.id.container, loanAccountApproval) @@ -300,7 +300,7 @@ class LoanAccountSummaryFragment : ProgressableFragment(), LoanAccountSummaryMvp fun disburseLoan() { val loanAccountDisbursement: LoanAccountDisbursementFragment = LoanAccountDisbursementFragment.Companion.newInstance(loanAccountNumber) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_LOAN_ACCOUNT_SUMMARY) fragmentTransaction.replace(R.id.container, loanAccountDisbursement) @@ -309,7 +309,7 @@ class LoanAccountSummaryFragment : ProgressableFragment(), LoanAccountSummaryMvp fun loadLoanDataTables() { val loanAccountFragment = DataTableFragment.newInstance(Constants.DATA_TABLE_NAME_LOANS, loanAccountNumber) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_LOAN_ACCOUNT_SUMMARY) fragmentTransaction.replace(R.id.container, loanAccountFragment) @@ -332,21 +332,21 @@ class LoanAccountSummaryFragment : ProgressableFragment(), LoanAccountSummaryMvp // if Loan is already active // the Transaction Would be Make Repayment view_status_indicator!!.setBackgroundColor( - ContextCompat.getColor(activity!!, R.color.light_green)) + ContextCompat.getColor(requireActivity(), R.color.light_green)) bt_processLoanTransaction!!.text = "Make Repayment" processLoanTransactionAction = TRANSACTION_REPAYMENT } else if (loanWithAssociations.status.pendingApproval) { // if Loan is Pending for Approval // the Action would be Approve Loan view_status_indicator!!.setBackgroundColor( - ContextCompat.getColor(activity!!, R.color.light_yellow)) + ContextCompat.getColor(requireActivity(), R.color.light_yellow)) bt_processLoanTransaction!!.text = "Approve Loan" processLoanTransactionAction = ACTION_APPROVE_LOAN } else if (loanWithAssociations.status.waitingForDisbursal) { // if Loan is Waiting for Disbursal // the Action would be Disburse Loan view_status_indicator!!.setBackgroundColor( - ContextCompat.getColor(activity!!, R.color.blue)) + ContextCompat.getColor(requireActivity(), R.color.blue)) bt_processLoanTransaction!!.text = "Disburse Loan" processLoanTransactionAction = ACTION_DISBURSE_LOAN } else if (loanWithAssociations.status.closedObligationsMet) { @@ -354,13 +354,13 @@ class LoanAccountSummaryFragment : ProgressableFragment(), LoanAccountSummaryMvp // if Loan is Closed after the obligations are met // the make payment will be disabled so that no more payment can be collected view_status_indicator!!.setBackgroundColor( - ContextCompat.getColor(activity!!, R.color.black)) + ContextCompat.getColor(requireActivity(), R.color.black)) bt_processLoanTransaction!!.isEnabled = false bt_processLoanTransaction!!.text = "Make Repayment" } else { inflateLoanSummary(loanWithAssociations) view_status_indicator!!.setBackgroundColor( - ContextCompat.getColor(activity!!, R.color.black)) + ContextCompat.getColor(requireActivity(), R.color.black)) bt_processLoanTransaction!!.isEnabled = false bt_processLoanTransaction!!.text = "Loan Closed" } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loancharge/LoanChargeFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loancharge/LoanChargeFragment.kt index ba87f773cc2..86a74d50d46 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loancharge/LoanChargeFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loancharge/LoanChargeFragment.kt @@ -4,7 +4,6 @@ */ package com.mifos.mifosxdroid.online.loancharge -import android.content.Context import android.os.Bundle import android.view.* import android.widget.ImageView @@ -21,20 +20,18 @@ import com.mifos.mifosxdroid.adapters.ChargeNameListAdapter import com.mifos.mifosxdroid.core.EndlessRecyclerOnScrollListener import com.mifos.mifosxdroid.core.MifosBaseActivity import com.mifos.mifosxdroid.core.MifosBaseFragment -import com.mifos.mifosxdroid.core.RecyclerItemClickListener import com.mifos.mifosxdroid.core.util.Toaster import com.mifos.mifosxdroid.dialogfragments.chargedialog.OnChargeCreateListener import com.mifos.mifosxdroid.dialogfragments.loanchargedialog.LoanChargeDialogFragment import com.mifos.objects.client.Charges import com.mifos.utils.Constants import com.mifos.utils.FragmentConstants -import java.util.* import javax.inject.Inject /** * Created by nellyk on 1/22/2016. */ -class LoanChargeFragment : MifosBaseFragment(), LoanChargeMvpView, RecyclerItemClickListener.OnItemClickListener, OnChargeCreateListener { +class LoanChargeFragment : MifosBaseFragment(), LoanChargeMvpView, OnChargeCreateListener { @kotlin.jvm.JvmField @BindView(R.id.rv_charge) var rv_charges: RecyclerView? = null @@ -62,12 +59,10 @@ class LoanChargeFragment : MifosBaseFragment(), LoanChargeMvpView, RecyclerItemC private var mChargesNameListAdapter: ChargeNameListAdapter? = null private lateinit var rootView: View private var loanAccountNumber = 0 - override fun onItemClick(childView: View, position: Int) {} - override fun onItemLongPress(childView: View, position: Int) {} override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) - if (arguments != null) loanAccountNumber = arguments!!.getInt(Constants.LOAN_ACCOUNT_NUMBER) + if (arguments != null) loanAccountNumber = requireArguments().getInt(Constants.LOAN_ACCOUNT_NUMBER) } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -78,7 +73,6 @@ class LoanChargeFragment : MifosBaseFragment(), LoanChargeMvpView, RecyclerItemC val layoutManager = LinearLayoutManager(activity) layoutManager.orientation = LinearLayoutManager.VERTICAL rv_charges!!.layoutManager = layoutManager - rv_charges!!.addOnItemTouchListener(RecyclerItemClickListener(activity, this)) rv_charges!!.setHasFixedSize(true) @@ -124,8 +118,7 @@ class LoanChargeFragment : MifosBaseFragment(), LoanChargeMvpView, RecyclerItemC override fun showLoanChargesList(charges: MutableList) { chargesList = charges - mChargesNameListAdapter = ChargeNameListAdapter(getContext(), - chargesList, loanAccountNumber) + mChargesNameListAdapter = ChargeNameListAdapter(chargesList, loanAccountNumber) rv_charges!!.adapter = mChargesNameListAdapter if (charges.size == 0) { ll_error!!.visibility = View.VISIBLE @@ -169,7 +162,7 @@ class LoanChargeFragment : MifosBaseFragment(), LoanChargeMvpView, RecyclerItemC val loanChargeDialogFragment = LoanChargeDialogFragment .newInstance(loanAccountNumber) loanChargeDialogFragment.setOnChargeCreateListener(this) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CHARGE_LIST) loanChargeDialogFragment.show(fragmentTransaction, "Loan Charge Dialog Fragment") diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepayment/LoanRepaymentFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepayment/LoanRepaymentFragment.kt index 17f7fbf8c5d..11afa9e3e98 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepayment/LoanRepaymentFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepayment/LoanRepaymentFragment.kt @@ -107,15 +107,12 @@ class LoanRepaymentFragment : MifosBaseFragment(), OnDatePickListener, LoanRepay override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) - if (arguments != null) { - val mLoanWithAssociations: LoanWithAssociations = arguments!!.getParcelable(Constants.LOAN_SUMMARY) - if (mLoanWithAssociations != null) { - clientName = mLoanWithAssociations.clientName - loanAccountNumber = mLoanWithAssociations.accountNo - loanId = mLoanWithAssociations.id.toString() - loanProductName = mLoanWithAssociations.loanProductName - amountInArrears = mLoanWithAssociations.summary.totalOverdue - } + arguments?.getParcelable(Constants.LOAN_SUMMARY)?.let { loanWithAssociations -> + clientName = loanWithAssociations.clientName + loanAccountNumber = loanWithAssociations.accountNo + loanId = loanWithAssociations.id.toString() + loanProductName = loanWithAssociations.loanProductName + amountInArrears = loanWithAssociations.summary.totalOverdue } } @@ -151,7 +148,7 @@ class LoanRepaymentFragment : MifosBaseFragment(), OnDatePickListener, LoanRepay override fun onClick(dialog: DialogInterface, which: Int) { if (DialogInterface.BUTTON_POSITIVE == which) { - activity!!.supportFragmentManager.popBackStackImmediate() + requireActivity().supportFragmentManager.popBackStackImmediate() } } @@ -242,7 +239,7 @@ class LoanRepaymentFragment : MifosBaseFragment(), OnDatePickListener, LoanRepay TODO Add Validation to make sure : 1. Date Is in Correct Format 2. Date Entered is not greater than Date Today i.e Date is not in future - */tv_repaymentDate!!.setOnClickListener { (mfDatePicker as MFDatePicker?)!!.show(activity!!.supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } + */tv_repaymentDate!!.setOnClickListener { (mfDatePicker as MFDatePicker?)!!.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } } /** @@ -297,7 +294,7 @@ class LoanRepaymentFragment : MifosBaseFragment(), OnDatePickListener, LoanRepay */ @OnClick(R.id.bt_cancelPayment) fun onCancelPaymentButtonClicked() { - activity!!.supportFragmentManager.popBackStackImmediate() + requireActivity().supportFragmentManager.popBackStackImmediate() } /** @@ -325,7 +322,7 @@ class LoanRepaymentFragment : MifosBaseFragment(), OnDatePickListener, LoanRepay tv_amountDue!!.text = loanRepaymentTemplate.amount.toString() inflateRepaymentDate() val listOfPaymentTypes = Utils.getPaymentTypeOptions(loanRepaymentTemplate.paymentTypeOptions) - val paymentTypeAdapter = ArrayAdapter(activity, + val paymentTypeAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, listOfPaymentTypes) paymentTypeAdapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item) @@ -352,7 +349,7 @@ class LoanRepaymentFragment : MifosBaseFragment(), OnDatePickListener, LoanRepay Toaster.show(rootView, "Payment Successful, Transaction ID = " + loanRepaymentResponse.resourceId) } - activity!!.supportFragmentManager.popBackStackImmediate() + requireActivity().supportFragmentManager.popBackStackImmediate() } override fun showError(errorMessage: Int) { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepaymentschedule/LoanRepaymentScheduleFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepaymentschedule/LoanRepaymentScheduleFragment.kt index c39de73c522..a49809c2560 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepaymentschedule/LoanRepaymentScheduleFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loanrepaymentschedule/LoanRepaymentScheduleFragment.kt @@ -50,7 +50,7 @@ class LoanRepaymentScheduleFragment : ProgressableFragment(), LoanRepaymentSched override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) - if (arguments != null) loanAccountNumber = arguments!!.getInt(Constants.LOAN_ACCOUNT_NUMBER) + if (arguments != null) loanAccountNumber = requireArguments().getInt(Constants.LOAN_ACCOUNT_NUMBER) setHasOptionsMenu(false) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loantransactions/LoanTransactionsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loantransactions/LoanTransactionsFragment.kt index 2209fba5dc9..0aca52498b9 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loantransactions/LoanTransactionsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loantransactions/LoanTransactionsFragment.kt @@ -36,7 +36,7 @@ class LoanTransactionsFragment : MifosBaseFragment(), LoanTransactionsMvpView { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) - if (arguments != null) loanAccountNumber = arguments!!.getInt(Constants.LOAN_ACCOUNT_NUMBER) + if (arguments != null) loanAccountNumber = requireArguments().getInt(Constants.LOAN_ACCOUNT_NUMBER) setHasOptionsMenu(false) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/note/NoteFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/note/NoteFragment.kt index 495b635b679..ff53a209a5b 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/note/NoteFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/note/NoteFragment.kt @@ -63,8 +63,8 @@ class NoteFragment : MifosBaseFragment(), NoteMvpView, OnRefreshListener { (activity as MifosBaseActivity?)!!.activityComponent.inject(this) notes = ArrayList() if (arguments != null) { - entityType = arguments!!.getString(Constants.ENTITY_TYPE) - entityId = arguments!!.getInt(Constants.ENTITY_ID) + entityType = requireArguments().getString(Constants.ENTITY_TYPE) + entityId = requireArguments().getInt(Constants.ENTITY_ID) } } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/runreports/reportcategory/ReportCategoryFragment.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/runreports/reportcategory/ReportCategoryFragment.java index 59ee4d55d9d..20cf3b6f5e3 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/runreports/reportcategory/ReportCategoryFragment.java +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/runreports/reportcategory/ReportCategoryFragment.java @@ -5,11 +5,6 @@ import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; -import androidx.annotation.Nullable; -import androidx.fragment.app.FragmentTransaction; -import androidx.recyclerview.widget.DividerItemDecoration; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -18,7 +13,6 @@ import com.mifos.mifosxdroid.adapters.ClientReportAdapter; import com.mifos.mifosxdroid.core.MifosBaseActivity; import com.mifos.mifosxdroid.core.MifosBaseFragment; -import com.mifos.mifosxdroid.core.RecyclerItemClickListener; import com.mifos.mifosxdroid.core.util.Toaster; import com.mifos.mifosxdroid.online.runreports.reportdetail.ReportDetailFragment; import com.mifos.objects.runreports.client.ClientReportTypeItem; @@ -28,6 +22,11 @@ import javax.inject.Inject; +import androidx.annotation.Nullable; +import androidx.fragment.app.FragmentTransaction; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import butterknife.BindView; import butterknife.ButterKnife; @@ -35,9 +34,7 @@ * Created by Tarun on 02-08-17. */ -public class ReportCategoryFragment extends MifosBaseFragment - implements ReportCategoryMvpView, - RecyclerItemClickListener.OnItemClickListener { +public class ReportCategoryFragment extends MifosBaseFragment implements ReportCategoryMvpView { @BindView(R.id.recycler_report) RecyclerView rvReports; @@ -45,7 +42,6 @@ public class ReportCategoryFragment extends MifosBaseFragment @Inject ReportCategoryPresenter presenter; - @Inject ClientReportAdapter reportAdapter; private View rootView; @@ -115,23 +111,16 @@ public void showReportCategories(List reportTypes) { rvReports.getContext(), layoutManager.getOrientation()); rvReports.setLayoutManager(layoutManager); rvReports.addItemDecoration(dividerItemDecoration); + reportAdapter = new ClientReportAdapter(position -> { + openDetailFragment(position); + return null; + }); rvReports.setAdapter(reportAdapter); - rvReports.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), this)); reportAdapter.setReportItems(reportTypes); reportAdapter.notifyDataSetChanged(); } - @Override - public void onItemClick(View childView, int position) { - openDetailFragment(position); - } - - @Override - public void onItemLongPress(View childView, int position) { - - } - private void openDetailFragment(int pos) { Bundle bundle = new Bundle(); bundle.putParcelable(Constants.CLIENT_REPORT_ITEM, reportTypeItems.get(pos)); diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingaccountsummary/SavingsAccountSummaryFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingaccountsummary/SavingsAccountSummaryFragment.kt index fbeb3c6ce78..22e0ed67332 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingaccountsummary/SavingsAccountSummaryFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingaccountsummary/SavingsAccountSummaryFragment.kt @@ -112,9 +112,9 @@ class SavingsAccountSummaryFragment : ProgressableFragment(), SavingsAccountSumm override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) if (arguments != null) { - savingsAccountNumber = arguments!!.getInt(Constants.SAVINGS_ACCOUNT_NUMBER) - savingsAccountType = arguments!!.getParcelable(Constants.SAVINGS_ACCOUNT_TYPE) - parentFragment = arguments!!.getBoolean(Constants.IS_A_PARENT_FRAGMENT) + savingsAccountNumber = requireArguments().getInt(Constants.SAVINGS_ACCOUNT_NUMBER) + savingsAccountType = requireArguments().getParcelable(Constants.SAVINGS_ACCOUNT_TYPE) + parentFragment = requireArguments().getBoolean(Constants.IS_A_PARENT_FRAGMENT) } inflateSavingsAccountSummary() setHasOptionsMenu(true) @@ -155,7 +155,7 @@ class SavingsAccountSummaryFragment : ProgressableFragment(), SavingsAccountSumm super.onDetach() mListener = null if (!parentFragment) { - activity!!.finish() + requireActivity().finish() } } @@ -196,7 +196,7 @@ class SavingsAccountSummaryFragment : ProgressableFragment(), SavingsAccountSumm } else if (processSavingTransactionAction == ACTION_ACTIVATE_SAVINGS) { activateSavings() } else { - Log.i(activity!!.localClassName, + Log.i(requireActivity().localClassName, resources.getString(R.string.transaction_action_not_set)) } } @@ -241,7 +241,7 @@ class SavingsAccountSummaryFragment : ProgressableFragment(), SavingsAccountSumm fun loadDocuments() { val documentListFragment = DocumentListFragment.newInstance(Constants.ENTITY_TYPE_SAVINGS, savingsAccountNumber) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_SAVINGS_ACCOUNT_SUMMARY) fragmentTransaction.replace(R.id.container, documentListFragment) @@ -251,7 +251,7 @@ class SavingsAccountSummaryFragment : ProgressableFragment(), SavingsAccountSumm fun approveSavings() { val savingsAccountApproval = SavingsAccountApprovalFragment .newInstance(savingsAccountNumber, savingsAccountType) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_SAVINGS_ACCOUNT_SUMMARY) fragmentTransaction.replace(R.id.container, savingsAccountApproval) @@ -261,7 +261,7 @@ class SavingsAccountSummaryFragment : ProgressableFragment(), SavingsAccountSumm fun activateSavings() { val savingsAccountApproval = SavingsAccountActivateFragment .newInstance(savingsAccountNumber, savingsAccountType) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_SAVINGS_ACCOUNT_SUMMARY) fragmentTransaction.replace(R.id.container, savingsAccountApproval) @@ -270,7 +270,7 @@ class SavingsAccountSummaryFragment : ProgressableFragment(), SavingsAccountSumm fun loadSavingsDataTables() { val loanAccountFragment = DataTableFragment.newInstance(Constants.DATA_TABLE_NAME_SAVINGS, savingsAccountNumber) - val fragmentTransaction = activity!!.supportFragmentManager + val fragmentTransaction = requireActivity().supportFragmentManager .beginTransaction() fragmentTransaction.addToBackStack(FragmentConstants.FRAG_SAVINGS_ACCOUNT_SUMMARY) fragmentTransaction.replace(R.id.container, loanAccountFragment) @@ -350,8 +350,8 @@ class SavingsAccountSummaryFragment : ProgressableFragment(), SavingsAccountSumm fun showTransaction(i: Int) { val transaction = listOfAllTransactions[i] - val dialog = Dialog(context) - dialog.window.setBackgroundDrawableResource(android.R.color.transparent) + val dialog = Dialog(requireContext()) + dialog.window?.setBackgroundDrawableResource(android.R.color.transparent) dialog.setContentView(R.layout.transaction_detail_dialog_layout) val transactionId = dialog.findViewById(R.id.tv_transactionId) val date = dialog.findViewById(R.id.tv_date) @@ -374,7 +374,7 @@ class SavingsAccountSummaryFragment : ProgressableFragment(), SavingsAccountSumm override fun showSavingsActivatedSuccessfully(genericResponse: GenericResponse?) { Toast.makeText(activity, resources.getString(R.string.savings_account_activated), Toast.LENGTH_LONG).show() - activity!!.supportFragmentManager.popBackStack() + requireActivity().supportFragmentManager.popBackStack() } override fun showFetchingError(s: Int) { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingaccounttransaction/SavingsAccountTransactionFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingaccounttransaction/SavingsAccountTransactionFragment.kt index e82113221e3..a39d1f6547a 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingaccounttransaction/SavingsAccountTransactionFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingaccounttransaction/SavingsAccountTransactionFragment.kt @@ -80,11 +80,11 @@ class SavingsAccountTransactionFragment : ProgressableFragment(), OnDatePickList super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) if (arguments != null) { - savingsAccountNumber = arguments!!.getString(Constants.SAVINGS_ACCOUNT_NUMBER) - savingsAccountId = arguments!!.getInt(Constants.SAVINGS_ACCOUNT_ID) - transactionType = arguments!!.getString(Constants.SAVINGS_ACCOUNT_TRANSACTION_TYPE) - clientName = arguments!!.getString(Constants.CLIENT_NAME) - savingsAccountType = arguments!!.getParcelable(Constants.SAVINGS_ACCOUNT_TYPE) + savingsAccountNumber = requireArguments().getString(Constants.SAVINGS_ACCOUNT_NUMBER) + savingsAccountId = requireArguments().getInt(Constants.SAVINGS_ACCOUNT_ID) + transactionType = requireArguments().getString(Constants.SAVINGS_ACCOUNT_TRANSACTION_TYPE) + clientName = requireArguments().getString(Constants.CLIENT_NAME) + savingsAccountType = requireArguments().getParcelable(Constants.SAVINGS_ACCOUNT_TYPE) } } @@ -121,7 +121,7 @@ class SavingsAccountTransactionFragment : ProgressableFragment(), OnDatePickList .setTitle(R.string.sync_previous_transaction) .setMessage(R.string.dialog_message_sync_savingaccounttransaction) .setPositiveButton(R.string.dialog_action_ok - ) { dialog, which -> activity!!.supportFragmentManager.popBackStackImmediate() } + ) { dialog, which -> requireActivity().supportFragmentManager.popBackStackImmediate() } .setCancelable(false) .createMaterialDialog() .show() @@ -209,7 +209,7 @@ class SavingsAccountTransactionFragment : ProgressableFragment(), OnDatePickList @OnClick(R.id.bt_cancelTransaction) fun onCancelTransactionButtonClicked() { - activity!!.supportFragmentManager.popBackStackImmediate() + requireActivity().supportFragmentManager.popBackStackImmediate() } fun inflateRepaymentDate() { @@ -218,7 +218,7 @@ class SavingsAccountTransactionFragment : ProgressableFragment(), OnDatePickList // TODO Add Validation to make sure : // 1. Date Is in Correct Format // 2. Date Entered is not greater than Date Today i.e Date is not in future - tv_transactionDate!!.setOnClickListener { (mfDatePicker as MFDatePicker?)?.show(activity!!.supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } + tv_transactionDate!!.setOnClickListener { (mfDatePicker as MFDatePicker?)?.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } } override fun onDatePicked(date: String) { @@ -229,7 +229,7 @@ class SavingsAccountTransactionFragment : ProgressableFragment(), OnDatePickList if (savingsAccountTransactionTemplate != null) { val listOfPaymentTypes = Utils.getPaymentTypeOptions( savingsAccountTransactionTemplate.paymentTypeOptions) - val paymentTypeAdapter = ArrayAdapter(activity, + val paymentTypeAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, listOfPaymentTypes) paymentTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) sp_paymentType!!.adapter = paymentTypeAdapter @@ -256,7 +256,7 @@ class SavingsAccountTransactionFragment : ProgressableFragment(), OnDatePickList + savingsAccountTransactionResponse.resourceId) } } - activity!!.supportFragmentManager.popBackStackImmediate() + requireActivity().supportFragmentManager.popBackStackImmediate() } override fun showError(errorMessage: Int) { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccount/SavingsAccountFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccount/SavingsAccountFragment.kt index e5a9d8404b0..856cf5d93ea 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccount/SavingsAccountFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccount/SavingsAccountFragment.kt @@ -154,13 +154,13 @@ class SavingsAccountFragment : ProgressableDialogFragment(), OnDatePickListener, } fun inflateSavingsSpinners() { - mFieldOfficerAdapter = ArrayAdapter(activity, + mFieldOfficerAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, mFieldOfficerNames) mFieldOfficerAdapter!! .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spFieldOfficer!!.adapter = mFieldOfficerAdapter spFieldOfficer!!.onItemSelectedListener = this - mSavingProductsAdapter = ArrayAdapter(activity, android.R.layout.simple_spinner_item, mListSavingProductsNames) + mSavingProductsAdapter = ArrayAdapter(requireActivity(), android.R.layout.simple_spinner_item, mListSavingProductsNames) mSavingProductsAdapter!!.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spProduct!!.adapter = mSavingProductsAdapter spProduct!!.onItemSelectedListener = this @@ -211,7 +211,7 @@ class SavingsAccountFragment : ProgressableDialogFragment(), OnDatePickListener, @OnClick(R.id.tv_submittedon_date) fun onClickTextViewSubmissionDate() { - mfDatePicker!!.show(activity!!.supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) + mfDatePicker!!.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } fun setSubmissionDate() { @@ -240,7 +240,7 @@ class SavingsAccountFragment : ProgressableDialogFragment(), OnDatePickListener, Toast.makeText(activity, resources.getString(R.string.savings_account_submitted_for_approval), Toast.LENGTH_LONG).show() - activity!!.supportFragmentManager.popBackStackImmediate() + requireActivity().supportFragmentManager.popBackStackImmediate() } override fun showFetchingError(errorMessage: Int) { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccountactivate/SavingsAccountActivateFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccountactivate/SavingsAccountActivateFragment.kt index d656dcc056a..0b82f993aaa 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccountactivate/SavingsAccountActivateFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccountactivate/SavingsAccountActivateFragment.kt @@ -68,15 +68,15 @@ class SavingsAccountActivateFragment : MifosBaseFragment(), OnDatePickListener, super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) if (arguments != null) { - savingsAccountNumber = arguments!!.getInt(Constants.SAVINGS_ACCOUNT_NUMBER) - savingsAccountType = arguments!!.getParcelable(Constants.SAVINGS_ACCOUNT_TYPE) + savingsAccountNumber = requireArguments().getInt(Constants.SAVINGS_ACCOUNT_NUMBER) + savingsAccountType = requireArguments().getParcelable(Constants.SAVINGS_ACCOUNT_TYPE) } setHasOptionsMenu(true) } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { // Inflate the layout for this fragment - if (activity!!.actionBar != null) activity!!.actionBar.setDisplayHomeAsUpEnabled(true) + activity?.actionBar?.setDisplayHomeAsUpEnabled(true) rootView = inflater.inflate(R.layout.dialog_fragment_approve_savings, null) ButterKnife.bind(this, rootView) mSavingsAccountActivatePresenter!!.attachView(this) @@ -106,7 +106,7 @@ class SavingsAccountActivateFragment : MifosBaseFragment(), OnDatePickListener, @OnClick(R.id.tv_approval_date) fun onClickApprovalDate() { - mfDatePicker!!.show(activity!!.supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) + mfDatePicker!!.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } override fun onDatePicked(date: String) { @@ -124,7 +124,7 @@ class SavingsAccountActivateFragment : MifosBaseFragment(), OnDatePickListener, Toaster.show(tvActivateDateHeading, resources.getString(R.string.savings_account_activated)) Toast.makeText(activity, "Savings Activated", Toast.LENGTH_LONG).show() - activity!!.supportFragmentManager.popBackStack() + requireActivity().supportFragmentManager.popBackStack() } override fun showError(message: String?) { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccountapproval/SavingsAccountApprovalFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccountapproval/SavingsAccountApprovalFragment.kt index b3b36b0d2a5..c71854b4dd0 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccountapproval/SavingsAccountApprovalFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccountapproval/SavingsAccountApprovalFragment.kt @@ -58,15 +58,15 @@ class SavingsAccountApprovalFragment : MifosBaseFragment(), OnDatePickListener, super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) if (arguments != null) { - savingsAccountNumber = arguments!!.getInt(Constants.SAVINGS_ACCOUNT_NUMBER) - savingsAccountType = arguments!!.getParcelable(Constants.SAVINGS_ACCOUNT_TYPE) + savingsAccountNumber = requireArguments().getInt(Constants.SAVINGS_ACCOUNT_NUMBER) + savingsAccountType = requireArguments().getParcelable(Constants.SAVINGS_ACCOUNT_TYPE) } setHasOptionsMenu(true) } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { // Inflate the layout for this fragment - if (activity!!.actionBar != null) activity!!.actionBar.setDisplayHomeAsUpEnabled(true) + activity?.actionBar?.setDisplayHomeAsUpEnabled(true) rootView = inflater.inflate(R.layout.dialog_fragment_approve_savings, null) ButterKnife.bind(this, rootView) mSavingsAccountApprovalPresenter!!.attachView(this) @@ -99,7 +99,7 @@ class SavingsAccountApprovalFragment : MifosBaseFragment(), OnDatePickListener, @OnClick(R.id.tv_approval_date) fun onClickApprovalDate() { - mfDatePicker!!.show(activity!!.supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) + mfDatePicker!!.show(requireActivity().supportFragmentManager, FragmentConstants.DFRAG_DATE_PICKER) } override fun onDatePicked(date: String) { @@ -120,7 +120,7 @@ class SavingsAccountApprovalFragment : MifosBaseFragment(), OnDatePickListener, override fun showSavingAccountApprovedSuccessfully(genericResponse: GenericResponse?) { Toast.makeText(activity, "Savings Approved", Toast.LENGTH_LONG).show() - activity!!.supportFragmentManager.popBackStack() + requireActivity().supportFragmentManager.popBackStack() } override fun showError(message: String?) { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/search/SearchFragment.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/search/SearchFragment.java index a640a8657d9..d727c8230ae 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/search/SearchFragment.java +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/search/SearchFragment.java @@ -7,8 +7,6 @@ import android.content.Intent; import android.os.Bundle; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; @@ -29,7 +27,6 @@ import com.mifos.mifosxdroid.adapters.SearchAdapter; import com.mifos.mifosxdroid.core.MifosBaseActivity; import com.mifos.mifosxdroid.core.MifosBaseFragment; -import com.mifos.mifosxdroid.core.RecyclerItemClickListener; import com.mifos.mifosxdroid.core.util.Toaster; import com.mifos.mifosxdroid.online.CentersActivity; import com.mifos.mifosxdroid.online.ClientActivity; @@ -46,6 +43,8 @@ import javax.inject.Inject; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import butterknife.BindArray; import butterknife.BindView; import butterknife.ButterKnife; @@ -53,8 +52,7 @@ import uk.co.deanwild.materialshowcaseview.MaterialShowcaseSequence; import uk.co.deanwild.materialshowcaseview.ShowcaseConfig; -public class SearchFragment extends MifosBaseFragment implements SearchMvpView, - RecyclerItemClickListener.OnItemClickListener, AdapterView.OnItemSelectedListener { +public class SearchFragment extends MifosBaseFragment implements SearchMvpView, AdapterView.OnItemSelectedListener { private static final String LOG_TAG = SearchFragment.class.getSimpleName(); @@ -88,7 +86,6 @@ public class SearchFragment extends MifosBaseFragment implements SearchMvpView, @BindArray(R.array.search_options_values) String[] searchOptionsValues; - @Inject SearchAdapter searchAdapter; @Inject @@ -137,8 +134,39 @@ public void showUserInterface() { layoutManager = new LinearLayoutManager(getActivity()); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); rv_search.setLayoutManager(layoutManager); - rv_search.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), this)); rv_search.setHasFixedSize(true); + searchAdapter = new SearchAdapter(searchedEntity -> { + Intent activity = null; + switch (searchedEntity.getEntityType()) { + case Constants.SEARCH_ENTITY_LOAN: + activity = new Intent(getActivity(), ClientActivity.class); + activity.putExtra(Constants.LOAN_ACCOUNT_NUMBER, + searchedEntity.getEntityId()); + break; + case Constants.SEARCH_ENTITY_CLIENT: + activity = new Intent(getActivity(), ClientActivity.class); + activity.putExtra(Constants.CLIENT_ID, + searchedEntity.getEntityId()); + break; + case Constants.SEARCH_ENTITY_GROUP: + activity = new Intent(getActivity(), GroupsActivity.class); + activity.putExtra(Constants.GROUP_ID, + searchedEntity.getEntityId()); + break; + case Constants.SEARCH_ENTITY_SAVING: + activity = new Intent(getActivity(), ClientActivity.class); + activity.putExtra(Constants.SAVINGS_ACCOUNT_NUMBER, + searchedEntity.getEntityId()); + break; + case Constants.SEARCH_ENTITY_CENTER: + activity = new Intent(getActivity(), CentersActivity.class); + activity.putExtra(Constants.CENTER_ID, + searchedEntity.getEntityId()); + break; + } + startActivity(activity); + return null; + }); rv_search.setAdapter(searchAdapter); cb_exactMatch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @@ -281,44 +309,6 @@ public void onPause() { super.onPause(); } - @Override - public void onItemClick(View childView, int position) { - Intent activity = null; - switch (searchedEntities.get(position).getEntityType()) { - case Constants.SEARCH_ENTITY_LOAN: - activity = new Intent(getActivity(), ClientActivity.class); - activity.putExtra(Constants.LOAN_ACCOUNT_NUMBER, - searchedEntities.get(position).getEntityId()); - break; - case Constants.SEARCH_ENTITY_CLIENT: - activity = new Intent(getActivity(), ClientActivity.class); - activity.putExtra(Constants.CLIENT_ID, - searchedEntities.get(position).getEntityId()); - break; - case Constants.SEARCH_ENTITY_GROUP: - activity = new Intent(getActivity(), GroupsActivity.class); - activity.putExtra(Constants.GROUP_ID, - searchedEntities.get(position).getEntityId()); - break; - case Constants.SEARCH_ENTITY_SAVING: - activity = new Intent(getActivity(), ClientActivity.class); - activity.putExtra(Constants.SAVINGS_ACCOUNT_NUMBER, - searchedEntities.get(position).getEntityId()); - break; - case Constants.SEARCH_ENTITY_CENTER: - activity = new Intent(getActivity(), CentersActivity.class); - activity.putExtra(Constants.CENTER_ID, - searchedEntities.get(position).getEntityId()); - break; - } - startActivity(activity); - } - - @Override - public void onItemLongPress(View childView, int position) { - - } - @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { if (parent.getId() == R.id.sp_search) { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/sign/SignatureFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/sign/SignatureFragment.kt index e10264792cb..b90a61be5e1 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/sign/SignatureFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/sign/SignatureFragment.kt @@ -47,7 +47,7 @@ class SignatureFragment : MifosBaseFragment(), SignatureMvpView, BottomNavigatio safeUIBlockingUtility = SafeUIBlockingUtility(activity, getString(R.string.signature_fragment_loading_message)) if (arguments != null) { - mClientId = arguments!!.getInt(Constants.CLIENT_ID) + mClientId = requireArguments().getInt(Constants.CLIENT_ID) } setHasOptionsMenu(true) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListFragment.kt index b3e5bbb2540..4261927b735 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/surveylist/SurveyListFragment.kt @@ -51,7 +51,7 @@ class SurveyListFragment : ProgressableFragment(), SurveyListMvpView { super.onCreate(savedInstanceState) (activity as MifosBaseActivity?)!!.activityComponent.inject(this) if (arguments != null) { - clientId = arguments!!.getInt(Constants.CLIENT_ID) + clientId = requireArguments().getInt(Constants.CLIENT_ID) } } @@ -83,7 +83,7 @@ class SurveyListFragment : ProgressableFragment(), SurveyListMvpView { } override fun onOptionsItemSelected(item: MenuItem): Boolean { - if (item.itemId == R.id.mItem_search) activity!!.finish() + if (item.itemId == R.id.mItem_search) requireActivity().finish() return super.onOptionsItemSelected(item) }