Skip to content

Commit

Permalink
## showing progress while loading countries json from assets
Browse files Browse the repository at this point in the history
  • Loading branch information
fawzy committed Oct 2, 2019
1 parent 4ce75d7 commit ad2b412
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dialog.plus.ui;

import android.app.ProgressDialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
Expand All @@ -20,7 +21,7 @@
import com.daimajia.androidanimations.library.YoYo;
import com.dialog.plus.R;
import com.dialog.plus.utils.AnimationUtils;
import com.dialog.plus.utils.KeyboardUtil;
import com.dialog.plus.utils.CommonUtil;
import com.dialog.plus.utils.SampleAnimationListener;

/**
Expand All @@ -35,6 +36,7 @@ public abstract class BaseDialogFragment<Binding extends ViewDataBinding> extend
protected Binding binding;
protected View mDialogView;
private AnimationSet mModalInAnim, mModalOutAnim;
private ProgressDialog mProgressDialog;

@Override
public View onCreateView(@androidx.annotation.NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Expand Down Expand Up @@ -104,11 +106,24 @@ protected void shakeView(EditText editText) {
}

protected void hideKeyboard(View view) {
KeyboardUtil.getInstance().hideKeyboard(view);
CommonUtil.getInstance().hideKeyboard(view);
}

protected void showKeyboard(View view) {
KeyboardUtil.getInstance().showKeyboard(view);
CommonUtil.getInstance().showKeyboard(view);
}

public void showLoading() {
hideLoading();
if (mProgressDialog == null)
mProgressDialog = CommonUtil.getInstance().getProgressDialog(getContext());
mProgressDialog.show();
}

public void hideLoading() {
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.cancel();
}
}

protected abstract Object getVariableValue();
Expand Down
6 changes: 4 additions & 2 deletions dialogPlus/src/main/java/com/dialog/plus/ui/DialogPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.dialog.plus.R;
import com.dialog.plus.data.CountryRepo;
import com.dialog.plus.databinding.DialogPlusBinding;
import com.dialog.plus.utils.KeyboardUtil;
import com.dialog.plus.utils.CommonUtil;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down Expand Up @@ -98,11 +98,13 @@ private void setDialogType() {
}

private void setDialogCountriesRecycler() {
showLoading();
model.setCountryDataModels(new ArrayList<>(new CountryRepo(getContext()).getCountriesList()));
CountryListDialogAdapter listDialogAdapter = new CountryListDialogAdapter(this, model.getCountryDataModels()
, model.isShowCountryCode(), model.getCountriesDialogListener());
((RecyclerView) getDialogAddedView(R.id.recycler)).setAdapter(listDialogAdapter);
setSearchTextWatcher(listDialogAdapter.getFilter());
hideLoading();
}


Expand Down Expand Up @@ -236,7 +238,7 @@ private void timeUp() {
model.setTimeLeft(0);
getDialogAddedView(R.id.sendCode).setClickable(false);
getDialogAddedView(R.id.txtPinEntry).setEnabled(false);
KeyboardUtil.getInstance().hideKeyboard(binding.getRoot());
CommonUtil.getInstance().hideKeyboard(binding.getRoot());
if (getContext() != null)
getDialogAddedView(R.id.sendCode).setBackgroundColor(ContextCompat.getColor(getContext(), R.color.carbon_grey_300));
if (model.getCodeTypeListener() != null)
Expand Down
52 changes: 52 additions & 0 deletions dialogPlus/src/main/java/com/dialog/plus/utils/CommonUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.dialog.plus.utils;

import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import static android.content.Context.INPUT_METHOD_SERVICE;
import static android.view.Gravity.CENTER;

/**
* Created by Muhammad Noamany
* [email protected]
*/
public class CommonUtil {
private static CommonUtil commonUtil;

public static CommonUtil getInstance() {
if (commonUtil == null)
commonUtil = new CommonUtil();
return commonUtil;
}

public ProgressDialog getProgressDialog(Context context) {
ProgressDialog progressDialog = new ProgressDialog(context);
if (progressDialog.getWindow() != null) {
progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
progressDialog.getWindow().setGravity(CENTER);
}
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setProgress(0);
// progressDialog.setContentView(R.layout.progress_dialog);
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
progressDialog.setCanceledOnTouchOutside(false);
return progressDialog;
}

public void showKeyboard(View view) {
InputMethodManager inputMethodManager = (InputMethodManager) view.getContext().getSystemService(INPUT_METHOD_SERVICE);
view.requestFocus();
inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_FORCED);
}

public void hideKeyboard(View view) {
final InputMethodManager inputMethodManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
view.clearFocus();
}
}
32 changes: 0 additions & 32 deletions dialogPlus/src/main/java/com/dialog/plus/utils/KeyboardUtil.java

This file was deleted.

0 comments on commit ad2b412

Please sign in to comment.