.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
|
||||
package com.ssb.simplitend.appblocking;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
public class AppList {
|
||||
private final String name;
|
||||
Drawable icon;
|
||||
private final String packages;
|
||||
public AppList(String name, Drawable icon, String packages) {
|
||||
this.name = name;
|
||||
this.icon = icon;
|
||||
this.packages = packages;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public Drawable getIcon() {
|
||||
return icon;
|
||||
}
|
||||
public String getPackages() {
|
||||
return packages;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.ssb.simplitend.appblocking;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.ssb.simplitend.R;
|
||||
|
||||
public class BlockApp extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.overlay_layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
package com.ssb.simplitend.appblocking;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class FUAActivity extends AppCompatActivity {
|
||||
|
||||
private static final String TAG = "aditya";
|
||||
|
||||
SwitchCompat swBlock;
|
||||
RecyclerView rvApps, rvWhiteApps;
|
||||
MyAppsAdapter adapter, whiteListAdapter;
|
||||
MySharedPref mySharedPref;
|
||||
List<AppList> whiteList;
|
||||
|
||||
List<AppList> installed_app_list;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_fua);
|
||||
|
||||
swBlock = (SwitchCompat) findViewById(R.id.swBlock);
|
||||
rvApps = (RecyclerView) findViewById(R.id.rvApps);
|
||||
rvWhiteApps = (RecyclerView) findViewById(R.id.rv_white_apps);
|
||||
mySharedPref = new MySharedPref(FUAActivity.this);
|
||||
|
||||
if (!isAccessibilityAppBlockingEnabled()) {
|
||||
openAccessibilityDialog();
|
||||
}
|
||||
|
||||
Intent serviceIntent = new Intent(getApplicationContext(), TopAppDetectionService.class);
|
||||
getApplicationContext().startService(serviceIntent);
|
||||
|
||||
whiteList = getWhiteListApps();
|
||||
Collections.sort(whiteList, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
|
||||
|
||||
adapter = new MyAppsAdapter(FUAActivity.this, getInstalledApps(), false, appList -> {
|
||||
if (!isContainsWhiteList(appList)) {
|
||||
whiteList.add(appList);
|
||||
Collections.sort(whiteList, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
|
||||
} else {
|
||||
whiteList.remove(getPosition(appList));
|
||||
}
|
||||
|
||||
whiteListAdapter.notifyDataSetChanged();
|
||||
});
|
||||
|
||||
whiteListAdapter = new MyAppsAdapter(FUAActivity.this, whiteList, true, new MyAppsAdapter.ItemClicked() {
|
||||
@Override
|
||||
public void onCLick(AppList appList) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
rvApps.setLayoutManager(new GridLayoutManager(this, 4));
|
||||
rvApps.setAdapter(adapter);
|
||||
|
||||
rvWhiteApps.setLayoutManager(new GridLayoutManager(this, 4));
|
||||
rvWhiteApps.setAdapter(whiteListAdapter);
|
||||
|
||||
swBlock.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
|
||||
if (!isAccessibilityAppBlockingEnabled() && isChecked) {
|
||||
Intent accessibilityIntent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
|
||||
startActivity(accessibilityIntent);
|
||||
}
|
||||
//
|
||||
// // Intent serviceIntent = new Intent(getApplicationContext(), service.class);
|
||||
//// ContextCompat.startForegroundService(getApplicationContext(), serviceIntent);
|
||||
//
|
||||
// // if (isChecked) {
|
||||
//
|
||||
// // startService(new Intent(MainActivity.this, ServiceTest.class));
|
||||
//
|
||||
//// Intent serviceIntent = new Intent(MainActivity.this, OverlayService.class);
|
||||
//// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
//// getApplicationContext().startForegroundService(serviceIntent);
|
||||
//// } else {
|
||||
//// getApplicationContext().startService(serviceIntent);
|
||||
//// }
|
||||
//
|
||||
// /* Intent serviceIntent = new Intent(MainActivity.this, OverlayService.class);
|
||||
// startService(serviceIntent);*/
|
||||
//
|
||||
// /* } else {
|
||||
// stopService(new Intent(MainActivity.this, OverlayService.class));
|
||||
// }*/
|
||||
|
||||
});
|
||||
|
||||
findViewById(R.id.done_btn).setOnClickListener(v -> {
|
||||
onBackPressed();
|
||||
});
|
||||
|
||||
findViewById(R.id.back_btn).setOnClickListener(v -> {
|
||||
onBackPressed();
|
||||
});
|
||||
}
|
||||
|
||||
private int getPosition(AppList appList) {
|
||||
for (int i = 0; i < whiteList.size(); i++) {
|
||||
if (whiteList.get(i).getPackages().equals(appList.getPackages())) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
private boolean isContainsWhiteList(AppList appList) {
|
||||
for (AppList appList1 : whiteList) {
|
||||
if (appList.getPackages().equals(appList1.getPackages())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<AppList> getWhiteListApps() {
|
||||
ArrayList<AppList> appsList = new ArrayList<>();
|
||||
|
||||
List<AppList> totalList = getInstalledApps();
|
||||
|
||||
for (AppList list : totalList) {
|
||||
if (!isSelectedApp(list.getPackages())) {
|
||||
appsList.add(list);
|
||||
}
|
||||
}
|
||||
|
||||
return appsList;
|
||||
}
|
||||
|
||||
public boolean isSelectedApp(String packageName) {
|
||||
if (mySharedPref.checkKey("APP_LIST")) {
|
||||
ArrayList<String> myList = new ArrayList<>(mySharedPref.getArrayList("APP_LIST"));
|
||||
return myList.contains(packageName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
swBlock.setChecked(isAccessibilityAppBlockingEnabled());
|
||||
}
|
||||
|
||||
private List<AppList> getInstalledApps() {
|
||||
if (installed_app_list != null) return installed_app_list;
|
||||
|
||||
PackageManager packageManager = getPackageManager();
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN, null);
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
|
||||
List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, 0);
|
||||
ArrayList<String> appsName = new ArrayList<>();
|
||||
List<AppList> apps = new ArrayList<>();
|
||||
|
||||
// Iterate over the resolved apps and extract their names
|
||||
for (ResolveInfo resolveInfo : resolveInfoList) {
|
||||
String appName1 = resolveInfo.loadLabel(packageManager).toString();
|
||||
Drawable icon = resolveInfo.loadIcon(packageManager);
|
||||
String packages = resolveInfo.activityInfo.packageName;
|
||||
apps.add(new AppList(appName1, icon, packages));
|
||||
appsName.add(packages);
|
||||
}
|
||||
|
||||
Collections.sort(apps, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
|
||||
Collections.sort(appsName);
|
||||
|
||||
if (mySharedPref.checkKey("APP_LIST")) {
|
||||
if (mySharedPref.getArrayList("APP_LIST").size() == 0) {
|
||||
mySharedPref.setArrayList("APP_LIST", appsName);
|
||||
}
|
||||
} else {
|
||||
mySharedPref.setArrayList("APP_LIST", appsName);
|
||||
}
|
||||
|
||||
return installed_app_list = apps;
|
||||
}
|
||||
|
||||
private boolean isAccessibilityAppBlockingEnabled() {
|
||||
int accessibilityEnabled = 0;
|
||||
final String service = getPackageName() + "/" + TopAppDetectionService.class.getCanonicalName();
|
||||
|
||||
try {
|
||||
accessibilityEnabled = Settings.Secure.getInt(
|
||||
getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_ENABLED);
|
||||
|
||||
} catch (Settings.SettingNotFoundException e) {
|
||||
Log.e("TAG", "Error finding setting, default accessibility to not found: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
|
||||
TextUtils.SimpleStringSplitter colonSplitter = new TextUtils.SimpleStringSplitter(':');
|
||||
|
||||
if (accessibilityEnabled == 1) {
|
||||
String settingValue = Settings.Secure.getString(
|
||||
getContentResolver(),
|
||||
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
|
||||
if (settingValue != null) {
|
||||
colonSplitter.setString(settingValue);
|
||||
while (colonSplitter.hasNext()) {
|
||||
String accessibilityService = colonSplitter.next();
|
||||
if (accessibilityService.equalsIgnoreCase(service)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isSystemPackage(PackageInfo pkgInfo) {
|
||||
return (pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
|
||||
}
|
||||
|
||||
private void openAccessibilityDialog() {
|
||||
|
||||
AppUtil.showAlert(this,
|
||||
"Accessibility Permission Dialog",
|
||||
"Please allow app blocking accessibility.",
|
||||
"Yes", (dialog, id) -> {
|
||||
Intent accessibilityIntent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
|
||||
startActivity(accessibilityIntent);
|
||||
},
|
||||
"No",(dialog, id) -> {
|
||||
// Action for 'NO' Button
|
||||
dialog.cancel();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
package com.ssb.simplitend.appblocking;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MyAppsAdapter extends RecyclerView.Adapter<MyAppsAdapter.ViewHolder> {
|
||||
private List<AppList> listdata;
|
||||
private Context context;
|
||||
private MySharedPref mySharedPref;
|
||||
boolean isWhiteList;
|
||||
ItemClicked itemClicked;
|
||||
|
||||
// RecyclerView recyclerView;
|
||||
public MyAppsAdapter(Context context, List<AppList> listdata, boolean isWhiteList, ItemClicked itemClicked) {
|
||||
this.context = context;
|
||||
this.listdata = listdata;
|
||||
this.isWhiteList = isWhiteList;
|
||||
this.itemClicked = itemClicked;
|
||||
mySharedPref = new MySharedPref(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
|
||||
View listItem = layoutInflater.inflate(R.layout.app_list_item, parent, false);
|
||||
ViewHolder viewHolder = new ViewHolder(listItem);
|
||||
return viewHolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
holder.tvAppName.setText(listdata.get(position).getName());
|
||||
holder.ivAppIcon.setImageDrawable(listdata.get(position).getIcon());
|
||||
|
||||
if (!isSelectedApp(listdata.get(position).getPackages())) {
|
||||
holder.ivAddRemove.setImageResource(R.drawable.minus);
|
||||
} else {
|
||||
holder.ivAddRemove.setImageResource(R.drawable.plus);
|
||||
}
|
||||
|
||||
if (isWhiteList) {
|
||||
holder.ivAddRemove.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
holder.ivAddRemove.setOnClickListener(v -> {
|
||||
|
||||
if (!isAccessibilityAppBlockingEnabled()) {
|
||||
openAccessibilityDialog();
|
||||
} else {
|
||||
addAppsInList(listdata.get(position).getPackages());
|
||||
|
||||
if (!isSelectedApp(listdata.get(position).getPackages())) {
|
||||
holder.ivAddRemove.setImageResource(R.drawable.minus);
|
||||
} else {
|
||||
holder.ivAddRemove.setImageResource(R.drawable.plus);
|
||||
}
|
||||
|
||||
itemClicked.onCLick(listdata.get(position));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public boolean isSelectedApp(String packageName) {
|
||||
if (mySharedPref.checkKey("APP_LIST")) {
|
||||
ArrayList<String> myList = new ArrayList<>(mySharedPref.getArrayList("APP_LIST"));
|
||||
return myList.contains(packageName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addAppsInList(String packageName) {
|
||||
ArrayList<String> myList = new ArrayList<>();
|
||||
|
||||
if (mySharedPref.checkKey("APP_LIST")) {
|
||||
|
||||
myList.addAll(mySharedPref.getArrayList("APP_LIST"));
|
||||
|
||||
if (myList.contains(packageName)) {
|
||||
myList.remove(packageName);
|
||||
mySharedPref.setArrayList("APP_LIST", myList);
|
||||
} else {
|
||||
myList.add(packageName);
|
||||
mySharedPref.setArrayList("APP_LIST", myList);
|
||||
}
|
||||
} else {
|
||||
myList.add(packageName);
|
||||
mySharedPref.setArrayList("APP_LIST", myList);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return listdata.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
interface ItemClicked {
|
||||
void onCLick(AppList appList);
|
||||
}
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView tvAppName;
|
||||
public ImageView ivAppIcon, ivAddRemove;
|
||||
public SwitchCompat swOnOff;
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
this.tvAppName = (TextView) itemView.findViewById(R.id.tvAppName);
|
||||
this.ivAppIcon = (ImageView) itemView.findViewById(R.id.iv_app_icon);
|
||||
this.ivAddRemove = (ImageView) itemView.findViewById(R.id.iv_add_remove);
|
||||
// this.swOnOff = (SwitchCompat) itemView.findViewById(R.id.swOnOff);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAccessibilityAppBlockingEnabled() {
|
||||
int accessibilityEnabled = 0;
|
||||
final String service = context.getPackageName() + "/" + TopAppDetectionService.class.getCanonicalName();
|
||||
|
||||
try {
|
||||
accessibilityEnabled = Settings.Secure.getInt(
|
||||
context.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_ENABLED);
|
||||
|
||||
} catch (Settings.SettingNotFoundException e) {
|
||||
Log.e("TAG", "Error finding setting, default accessibility to not found: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
|
||||
TextUtils.SimpleStringSplitter colonSplitter = new TextUtils.SimpleStringSplitter(':');
|
||||
|
||||
if (accessibilityEnabled == 1) {
|
||||
String settingValue = Settings.Secure.getString(
|
||||
context.getContentResolver(),
|
||||
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
|
||||
if (settingValue != null) {
|
||||
colonSplitter.setString(settingValue);
|
||||
while (colonSplitter.hasNext()) {
|
||||
String accessibilityService = colonSplitter.next();
|
||||
if (accessibilityService.equalsIgnoreCase(service)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void openAccessibilityDialog() {
|
||||
|
||||
AppUtil.showAlert(context,
|
||||
"Accessibility Permission Dialog",
|
||||
"Please allow app blocking accessibility.",
|
||||
"Yes", (dialog, id) -> {
|
||||
Intent accessibilityIntent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
|
||||
context.startActivity(accessibilityIntent);
|
||||
},
|
||||
"No",(dialog, id) -> {
|
||||
// Action for 'NO' Button
|
||||
dialog.cancel();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.ssb.simplitend.appblocking;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class MySharedPref {
|
||||
private static final String APP_SHARED_PREFS = "AppBlock";
|
||||
private SharedPreferences appSharedPrefs;
|
||||
private SharedPreferences.Editor prefsEditor;
|
||||
|
||||
public MySharedPref(Context activity) {
|
||||
this.appSharedPrefs = activity.getSharedPreferences(APP_SHARED_PREFS,
|
||||
Activity.MODE_PRIVATE);
|
||||
this.prefsEditor = appSharedPrefs.edit();
|
||||
}
|
||||
|
||||
public String getPrefsValue(String value) {
|
||||
return appSharedPrefs.getString(value, "");
|
||||
}
|
||||
|
||||
public void savePrefsValue(String key, String Value) {
|
||||
prefsEditor.putString(key, Value);
|
||||
prefsEditor.commit();
|
||||
}
|
||||
|
||||
public String getString(String value) {
|
||||
return appSharedPrefs.getString(value, "");
|
||||
}
|
||||
|
||||
public void saveString(String key, String Value) {
|
||||
prefsEditor.putString(key, Value);
|
||||
prefsEditor.commit();
|
||||
}
|
||||
|
||||
public Boolean checkKey(String Key) {
|
||||
if (appSharedPrefs.contains(Key))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public Set<String> getArrayList(String key) {
|
||||
return appSharedPrefs.getStringSet(key, null);
|
||||
}
|
||||
|
||||
public void setArrayList(String key, ArrayList<String> list) {
|
||||
Set<String> set = new HashSet<>(list);
|
||||
prefsEditor.putStringSet(key, set);
|
||||
prefsEditor.commit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.ssb.simplitend.appblocking;
|
||||
|
||||
import android.accessibilityservice.AccessibilityService;
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
|
||||
import com.ssb.simplitend.BuildConfig;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TopAppDetectionService extends AccessibilityService {
|
||||
MySharedPref sharedPref;
|
||||
List<String> appsList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onAccessibilityEvent(AccessibilityEvent event) {
|
||||
|
||||
Log.d("aditya", "onAccessibilityEvent: " + event);
|
||||
|
||||
sharedPref = new MySharedPref(getApplication());
|
||||
appsList.addAll(sharedPref.getArrayList("APP_LIST"));
|
||||
|
||||
Log.i("TAG--->", "onAccessibilityEvent: ==>" + sharedPref.getArrayList("APP_LIST"));
|
||||
|
||||
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
|
||||
// Get the package name of the currently opened app
|
||||
String packageName = event.getPackageName().toString();
|
||||
|
||||
Log.i("TAG--->", "onAccessibilityEvent: 1==>" + packageName);
|
||||
|
||||
if (sharedPref.checkKey("APP_LIST") &&
|
||||
!packageName.equals(BuildConfig.APPLICATION_ID) &&
|
||||
!packageName.equals("com.android.settings") &&
|
||||
!packageName.equals("com.google.android.googlequicksearchbox")) {
|
||||
|
||||
if (sharedPref.getArrayList("APP_LIST").contains(packageName)) {
|
||||
Intent intent = new Intent(this, BlockApp.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
// // Check if the package name matches the blocked app
|
||||
// for (String packageNames : appsList) {
|
||||
// if (packageNames.equals(packageName)) {
|
||||
// // Launch the parent app or show a blocking message
|
||||
// Intent intent = new Intent(this, BlockApp.class);
|
||||
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// startActivity(intent);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInterrupt() {
|
||||
// This method is required but not used in this example
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceConnected() {
|
||||
super.onServiceConnected();
|
||||
|
||||
sharedPref = new MySharedPref(getApplication());
|
||||
// Set the event types and package names to monitor
|
||||
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
|
||||
info.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
|
||||
info.packageNames = sharedPref.getArrayList("APP_LIST").toArray(new String[0]);
|
||||
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
|
||||
|
||||
// Set the flags based on the Android version
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
info.flags = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS |
|
||||
AccessibilityServiceInfo.FLAG_REPORT_VIEW_IDS;
|
||||
}
|
||||
|
||||
// Set the service info
|
||||
setServiceInfo(info);
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public void onTaskRemoved(Intent rootIntent) {
|
||||
Intent restartServiceIntent = new Intent(getApplicationContext(), this.getClass());
|
||||
restartServiceIntent.setPackage(getPackageName());
|
||||
startService(restartServiceIntent);
|
||||
super.onTaskRemoved(rootIntent);
|
||||
}*/
|
||||
}
|
||||
@@ -12,7 +12,6 @@ import androidx.lifecycle.ViewModelProvider;
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.CaregiverDataCache;
|
||||
import com.ssb.simplitend.articles.ArticlesActivity;
|
||||
import com.ssb.simplitend.caregiverdashboard.fragments.CaregiverChatsFragment;
|
||||
import com.ssb.simplitend.caregiverdashboard.fragments.CgDashBoardFragment;
|
||||
import com.ssb.simplitend.caregiverdashboard.fragments.MyPatientFragment;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.CaregiverMainViewModel;
|
||||
@@ -22,6 +21,7 @@ import com.ssb.simplitend.customsviews.MenuItem;
|
||||
import com.ssb.simplitend.databinding.CaregiverDashboardActivityBinding;
|
||||
import com.ssb.simplitend.databinding.CaregiverDashboardMenuBinding;
|
||||
import com.ssb.simplitend.faqs.FAQ_Activity;
|
||||
import com.ssb.simplitend.patient_dashboard.chats.ChatFragment;
|
||||
import com.ssb.simplitend.welcome.welcomecg.mvvm.CareGiverData;
|
||||
import com.yarolegovich.slidingrootnav.SlidingRootNavBuilder;
|
||||
import com.yarolegovich.slidingrootnav.callback.DragStateListener;
|
||||
@@ -56,6 +56,21 @@ public class CaregiverDashActivity extends AppCompatActivity implements
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
Fragment fragment = getSupportFragmentManager().findFragmentByTag("chat");
|
||||
if (fragment != null){
|
||||
if (fragment instanceof ChatFragment){
|
||||
binding.bottomNav.selectMenuItem(MenuItem.DASHBOARD);
|
||||
onBottomNavItemSelected(MenuItem.DASHBOARD);
|
||||
}else{
|
||||
super.onBackPressed();
|
||||
}
|
||||
}else{
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
|
||||
// viewmodel
|
||||
@@ -77,7 +92,7 @@ public class CaregiverDashActivity extends AppCompatActivity implements
|
||||
binding.bottomNav.setItemSelectListener(this);
|
||||
|
||||
// initializing dashboard fragment
|
||||
replaceFragment(new CgDashBoardFragment());
|
||||
replaceFragment(new CgDashBoardFragment(), "dashboard");
|
||||
|
||||
setLayoutDetails();
|
||||
|
||||
@@ -147,9 +162,9 @@ public class CaregiverDashActivity extends AppCompatActivity implements
|
||||
menuBinding.name.setText(careGiverData.patientDetails.first_name);
|
||||
}
|
||||
|
||||
private void replaceFragment(Fragment fragment){
|
||||
private void replaceFragment(Fragment fragment, String tag){
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.fcv_cg_home, fragment)
|
||||
.replace(R.id.fcv_cg_home, fragment, tag)
|
||||
.commitAllowingStateLoss();
|
||||
}
|
||||
|
||||
@@ -173,9 +188,12 @@ public class CaregiverDashActivity extends AppCompatActivity implements
|
||||
@Override
|
||||
public void onBottomNavItemSelected(MenuItem selectedItem) {
|
||||
if (selectedItem == MenuItem.DASHBOARD){
|
||||
replaceFragment(new CgDashBoardFragment());
|
||||
replaceFragment(new CgDashBoardFragment(), "dashboard");
|
||||
|
||||
// setting up toolbar accordingly
|
||||
binding.toolbar.setVisibility(View.VISIBLE);
|
||||
binding.bottomNav.setVisibility(View.VISIBLE);
|
||||
|
||||
binding.toolbar.setNavigationIcon(AppCompatResources.getDrawable(this, R.drawable.ic_menu));
|
||||
binding.toolbar.setNavigationIconTint(getResources().getColor(R.color.black));
|
||||
|
||||
@@ -190,17 +208,20 @@ public class CaregiverDashActivity extends AppCompatActivity implements
|
||||
binding.toolbar.setTitle("Welcome " + first_name);
|
||||
|
||||
}else if (selectedItem == MenuItem.MY_PATIENT){
|
||||
replaceFragment(new MyPatientFragment());
|
||||
replaceFragment(new MyPatientFragment(), "my_patient");
|
||||
|
||||
// setting up toolbar accordingly
|
||||
binding.toolbar.setVisibility(View.VISIBLE);
|
||||
binding.bottomNav.setVisibility(View.VISIBLE);
|
||||
|
||||
binding.toolbar.setTitle(null);
|
||||
binding.toolbar.setNavigationIcon(AppCompatResources.getDrawable(this, R.drawable.ic_menu));
|
||||
binding.toolbar.setNavigationIconTint(getResources().getColor(R.color.white));
|
||||
}else if (selectedItem == MenuItem.CHATS){
|
||||
replaceFragment(new CaregiverChatsFragment());
|
||||
binding.toolbar.setNavigationIcon(AppCompatResources.getDrawable(this, R.drawable.ic_menu));
|
||||
binding.toolbar.setNavigationIconTint(getResources().getColor(R.color.black));
|
||||
binding.toolbar.setTitle("Chats");
|
||||
replaceFragment(new ChatFragment(), "chat");
|
||||
|
||||
binding.toolbar.setVisibility(View.GONE);
|
||||
binding.bottomNav.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.ssb.simplitend.caregiverdashboard.activities;
|
||||
|
||||
import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
|
||||
import static com.ssb.simplitend.caregiverdashboard.activities.EditProfileInfoActivity.IS_CAREGIVER;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.biometric.BiometricManager;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -70,9 +73,27 @@ public class CaregiverProfileActivity extends AppCompatActivity implements Compo
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
checkIfBiometricAvailable();
|
||||
|
||||
binding.biometricCheck.setOnCheckedChangeListener(this);
|
||||
}
|
||||
|
||||
private void checkIfBiometricAvailable() {
|
||||
|
||||
BiometricManager biometricManager = BiometricManager.from(this);
|
||||
|
||||
switch (biometricManager.canAuthenticate(BIOMETRIC_STRONG)) {
|
||||
case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
|
||||
case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
|
||||
binding.biometricCheckView.setVisibility(View.GONE);
|
||||
break;
|
||||
case BiometricManager.BIOMETRIC_SUCCESS:
|
||||
case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
|
||||
binding.biometricCheckView.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void clickEvents() {
|
||||
binding.backBtn.setOnClickListener(v -> onBackPressed());
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.ssb.simplitend.caregiverdashboard.fragments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.ssb.simplitend.databinding.CaregiverChatsFragmentBinding;
|
||||
|
||||
public class CaregiverChatsFragment extends Fragment {
|
||||
|
||||
// view binding
|
||||
protected CaregiverChatsFragmentBinding binding;
|
||||
|
||||
public CaregiverChatsFragment(){
|
||||
// required empty
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = CaregiverChatsFragmentBinding.inflate(inflater, container, false);
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import static com.ssb.simplitend.caregiverdashboard.activities.PatientProfileSho
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -37,6 +38,8 @@ public class MyPatientFragment extends Fragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = MyPatientFragmentBinding.inflate(inflater, container, false);
|
||||
|
||||
adjustLayout();
|
||||
|
||||
initViews();
|
||||
|
||||
clickEvents();
|
||||
@@ -44,6 +47,20 @@ public class MyPatientFragment extends Fragment {
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
// adjusts the guideline percentage w.r.t the aspect ratio of the screen
|
||||
private void adjustLayout() {
|
||||
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
|
||||
int screenWidth = displayMetrics.widthPixels;
|
||||
int screenHeight = displayMetrics.heightPixels;
|
||||
|
||||
// Calculate aspect ratio
|
||||
float aspectRatio = (float) screenHeight / (float) screenWidth;
|
||||
|
||||
if (aspectRatio < 2.03f){
|
||||
binding.guideline.setGuidelinePercent(0.55f);
|
||||
}
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
CaregiverDataCache.getCaregiverData(requireContext(), (careGiverData1 -> {
|
||||
this.careGiverData = careGiverData1;
|
||||
|
||||
@@ -83,7 +83,7 @@ public class HomeBottomNav extends FrameLayout {
|
||||
this.itemSelectListener = itemSelectListener;
|
||||
}
|
||||
|
||||
private void selectMenuItem(MenuItem menuitem){
|
||||
public void selectMenuItem(MenuItem menuitem){
|
||||
|
||||
clearItemSelection(this.selected_item);
|
||||
|
||||
|
||||
@@ -24,8 +24,6 @@ public class ChatFragment extends Fragment {
|
||||
// view binding
|
||||
protected ChatFragmentBinding binding;
|
||||
|
||||
// chat item
|
||||
private ChatItem chatItem;
|
||||
public static final String CHAT_ITEM_KEY = "chat_item_key";
|
||||
|
||||
private MessagesListAdapter<Message> messageAdapter;
|
||||
@@ -64,21 +62,7 @@ public class ChatFragment extends Fragment {
|
||||
|
||||
private void initViews() {
|
||||
|
||||
Bundle bundle = getArguments();
|
||||
|
||||
if (bundle == null) {
|
||||
Toast.makeText(requireActivity(), "Something went wrong", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
chatItem = (ChatItem) bundle.getSerializable(CHAT_ITEM_KEY);
|
||||
|
||||
if (chatItem == null) {
|
||||
Toast.makeText(requireActivity(), "Something went wrong", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
binding.chatTitle.setText(chatItem.name);
|
||||
binding.chatTitle.setText("Aditya");
|
||||
|
||||
MessagesListAdapter.HoldersConfig holdersConfig = new MessagesListAdapter.HoldersConfig();
|
||||
holdersConfig.setOutcomingLayout(R.layout.sender_msg_viewholder);
|
||||
@@ -97,7 +81,5 @@ public class ChatFragment extends Fragment {
|
||||
messageAdapter.addToStart(new Message(new Receiver(), "Good morning mate!"), true);
|
||||
messageAdapter.addToStart(new Message(new Author(), "Good morning"), true);
|
||||
messageAdapter.addToStart(new Message(new Receiver(), "Good morning mate!"), true);
|
||||
|
||||
messageAdapter.addToStart(new Message(new Receiver(), chatItem.last_message), true);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.navigation.Navigation;
|
||||
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.appblocking.FUAActivity;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.PatientDataCache;
|
||||
import com.ssb.simplitend.databinding.PatientDashboardFragmentBinding;
|
||||
@@ -124,6 +125,11 @@ public class PatientDashboardFragment extends Fragment {
|
||||
binding.profile.setOnClickListener(v -> {
|
||||
Navigation.findNavController(v).navigate(R.id.action_CPDashboardFragment_to_patientProfileInfoFragment);
|
||||
});
|
||||
|
||||
binding.apps.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(requireActivity(), FUAActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
||||
private void updateTime() {
|
||||
|
||||
@@ -18,13 +18,9 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.PatientDataCache;
|
||||
import com.ssb.simplitend.caregiverdashboard.activities.EditProfileInfoActivity;
|
||||
import com.ssb.simplitend.caregiverdashboard.activities.PatientProfileShowerActivity;
|
||||
import com.ssb.simplitend.cg_geofencing.CgGeoFencingActivity;
|
||||
import com.ssb.simplitend.databinding.ActivityPatProfileInfoBinding;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ReminderFragment extends Fragment implements RecyclerTouchListener.
|
||||
ProfileContracts.GetRemindersListCallback, ProfileContracts.ReminderDeleteCallback,
|
||||
ProfileContracts.AddReminderCallBack,
|
||||
ReminderAdapter.ReminderCheckClickListener,
|
||||
ReminderAdapter.ReminderClickListener{
|
||||
ReminderAdapter.ReminderClickListener {
|
||||
|
||||
// view binding
|
||||
protected RemindersFragmentBinding binding;
|
||||
@@ -104,34 +104,34 @@ public class ReminderFragment extends Fragment implements RecyclerTouchListener.
|
||||
|
||||
// add button
|
||||
binding.addReminder.setOnClickListener(v ->
|
||||
{
|
||||
{
|
||||
|
||||
try {
|
||||
Navigation.findNavController(v).navigate(R.id.action_reminderFragment_to_addReminderFragment);
|
||||
}catch (Exception e){
|
||||
// there may be a IllegalStateException as this same fragment is used from another fragment
|
||||
// and not through the nav graph
|
||||
try {
|
||||
Navigation.findNavController(v).navigate(R.id.action_reminderFragment_to_addReminderFragment);
|
||||
} catch (Exception e) {
|
||||
// there may be a IllegalStateException as this same fragment is used from another fragment
|
||||
// and not through the nav graph
|
||||
|
||||
try {
|
||||
getParentFragmentManager().beginTransaction()
|
||||
.replace(R.id.fcv_profile_shower, AddReminderFragment.class, null)
|
||||
.addToBackStack("add_reminder")
|
||||
.commitAllowingStateLoss();
|
||||
} catch (Exception ex) {
|
||||
// user may be out of context
|
||||
try {
|
||||
getParentFragmentManager().beginTransaction()
|
||||
.replace(R.id.fcv_profile_shower, AddReminderFragment.class, null)
|
||||
.addToBackStack("add_reminder")
|
||||
.commitAllowingStateLoss();
|
||||
} catch (Exception ex) {
|
||||
// user may be out of context
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
binding.done.setOnClickListener(v -> {
|
||||
if (getActivity() != null){
|
||||
if (getActivity() != null) {
|
||||
getActivity().onBackPressed();
|
||||
}
|
||||
});
|
||||
|
||||
binding.backBtn.setOnClickListener(v -> {
|
||||
if (getActivity() != null){
|
||||
if (getActivity() != null) {
|
||||
getActivity().onBackPressed();
|
||||
}
|
||||
});
|
||||
@@ -426,7 +426,7 @@ public class ReminderFragment extends Fragment implements RecyclerTouchListener.
|
||||
try {
|
||||
Navigation.findNavController(binding.getRoot())
|
||||
.navigate(R.id.action_reminderFragment_to_addReminderFragment, bundle);
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
// there may be a IllegalStateException as this same fragment is used from another fragment
|
||||
// and not through the nav graph
|
||||
|
||||
@@ -463,37 +463,35 @@ public class ReminderFragment extends Fragment implements RecyclerTouchListener.
|
||||
@Override
|
||||
public void onCheck(ReminderResult reminderResult, int position) {
|
||||
// is user checking only today's check
|
||||
try {
|
||||
int today_date = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
|
||||
int selected_date = Integer.parseInt(weekDayViewsList.get(reminderViewModel.selected_dow).date.getText().toString());
|
||||
|
||||
if (reminderResult.reminder_marked == null) {
|
||||
/*
|
||||
now, we don't want to allow checking of routine of other day
|
||||
*/
|
||||
try {
|
||||
int today_date = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
|
||||
int selected_date = Integer.parseInt(weekDayViewsList.get(reminderViewModel.selected_dow).date.getText().toString());
|
||||
|
||||
if (today_date == selected_date) {
|
||||
AppUtil.showAlert(requireContext(),
|
||||
"Are you sure?",
|
||||
"Do yuo want to check this reminder?\nThis cannot be undone.",
|
||||
getString(R.string.yes),
|
||||
(dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
|
||||
updateRoutine(reminderResult, position);
|
||||
|
||||
}, getString(R.string.no),
|
||||
(dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
});
|
||||
} else {
|
||||
Toast.makeText(requireContext(), "Cannot mark future routine.", Toast.LENGTH_SHORT).show();
|
||||
if (today_date == selected_date) {
|
||||
if (reminderResult.reminder_marked != null){
|
||||
// already marked
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(requireContext(), "Couldn't be done.", Toast.LENGTH_SHORT).show();
|
||||
AppUtil.showAlert(requireContext(),
|
||||
"Are you sure?",
|
||||
"Do yuo want to check this reminder?\nThis cannot be undone.",
|
||||
getString(R.string.yes),
|
||||
(dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
|
||||
updateRoutine(reminderResult, position);
|
||||
|
||||
}, getString(R.string.no),
|
||||
(dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
});
|
||||
} else {
|
||||
Toast.makeText(requireContext(), "Cannot mark future routine.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(requireContext(), "Couldn't be done.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class RoutineFragment extends Fragment implements RoutineAdapter.ClickLis
|
||||
ProfileContracts.AddNUpdateRoutineCallback {
|
||||
|
||||
private static final String TAG = "RoutineFragment";
|
||||
|
||||
|
||||
// view binding
|
||||
protected RoutineFragmentBinding binding;
|
||||
|
||||
@@ -52,7 +52,7 @@ public class RoutineFragment extends Fragment implements RoutineAdapter.ClickLis
|
||||
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
public RoutineFragment(){
|
||||
public RoutineFragment() {
|
||||
// required empty const.
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ public class RoutineFragment extends Fragment implements RoutineAdapter.ClickLis
|
||||
});
|
||||
|
||||
binding.backBtn.setOnClickListener(v -> {
|
||||
if (getActivity() != null){
|
||||
if (getActivity() != null) {
|
||||
getActivity().onBackPressed();
|
||||
}
|
||||
});
|
||||
@@ -112,7 +112,7 @@ public class RoutineFragment extends Fragment implements RoutineAdapter.ClickLis
|
||||
try {
|
||||
|
||||
Navigation.findNavController(v).navigate(R.id.action_routineFragment_to_addRoutineFragment);
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
// there may be a IllegalStateException as this same fragment is used from another fragment
|
||||
// and not through the nav graph
|
||||
|
||||
@@ -128,7 +128,7 @@ public class RoutineFragment extends Fragment implements RoutineAdapter.ClickLis
|
||||
});
|
||||
|
||||
binding.done.setOnClickListener(v -> {
|
||||
if (getActivity() != null){
|
||||
if (getActivity() != null) {
|
||||
getActivity().onBackPressed();
|
||||
}
|
||||
});
|
||||
@@ -201,7 +201,7 @@ public class RoutineFragment extends Fragment implements RoutineAdapter.ClickLis
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
||||
for (int i = 0; i<7; i++){
|
||||
for (int i = 0; i < 7; i++) {
|
||||
WeekDayViewHolder dayViewHolder = weekDayViewsList.get(i);
|
||||
|
||||
dayViewHolder.day_of_week = calendar.get(Calendar.DAY_OF_WEEK);
|
||||
@@ -213,14 +213,14 @@ public class RoutineFragment extends Fragment implements RoutineAdapter.ClickLis
|
||||
}
|
||||
}
|
||||
|
||||
private void setDayOfWeek(int selection){
|
||||
private void setDayOfWeek(int selection) {
|
||||
|
||||
// setting selected date in adapter
|
||||
routineAdapter.setSelected_date(weekDayViewsList.get(selection).mDate);
|
||||
|
||||
clearSelection();
|
||||
|
||||
switch (routineViewModel.selected_dow = selection){
|
||||
switch (routineViewModel.selected_dow = selection) {
|
||||
case 0:
|
||||
binding.day.setBackgroundResource(R.drawable.seleted_item_primary);
|
||||
binding.dayT1.setTextColor(getResources().getColor(R.color.white_bg));
|
||||
@@ -266,8 +266,8 @@ public class RoutineFragment extends Fragment implements RoutineAdapter.ClickLis
|
||||
|
||||
}
|
||||
|
||||
private void clearSelection(){
|
||||
switch (routineViewModel.selected_dow){
|
||||
private void clearSelection() {
|
||||
switch (routineViewModel.selected_dow) {
|
||||
case 0:
|
||||
binding.day.setBackgroundColor(getResources().getColor(R.color.white_bg));
|
||||
binding.dayT1.setTextColor(getResources().getColor(R.color.black));
|
||||
@@ -340,13 +340,13 @@ public class RoutineFragment extends Fragment implements RoutineAdapter.ClickLis
|
||||
public void onRoutinesFetched(List<RoutineDetails> routineList) {
|
||||
progressDialog.dismiss();
|
||||
|
||||
if (routineList != null && routineList.size() > 0){
|
||||
if (routineList != null && routineList.size() > 0) {
|
||||
// reminders are present
|
||||
binding.routineRv.setVisibility(View.VISIBLE);
|
||||
binding.noData.setVisibility(View.GONE);
|
||||
|
||||
routineAdapter.submitList(routineList);
|
||||
}else{
|
||||
} else {
|
||||
binding.routineRv.setVisibility(View.GONE);
|
||||
binding.noData.setVisibility(View.VISIBLE);
|
||||
}
|
||||
@@ -372,7 +372,7 @@ public class RoutineFragment extends Fragment implements RoutineAdapter.ClickLis
|
||||
|
||||
AppUtil.showSOSDecision(requireContext(), getString(R.string.delete_med_routine),
|
||||
getString(R.string.yes), getString(R.string.no),
|
||||
v1-> {
|
||||
v1 -> {
|
||||
// yes click
|
||||
progressDialog.setTitle("Please wait...");
|
||||
progressDialog.setMessage("while we delete the routine for you.");
|
||||
@@ -400,7 +400,7 @@ public class RoutineFragment extends Fragment implements RoutineAdapter.ClickLis
|
||||
|
||||
try {
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.action_routineFragment_to_addRoutineFragment, bundle);
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
// there may be a IllegalStateException as this same fragment is used from another fragment
|
||||
// and not through the nav graph
|
||||
|
||||
@@ -418,37 +418,38 @@ public class RoutineFragment extends Fragment implements RoutineAdapter.ClickLis
|
||||
@Override
|
||||
public void onCheckClick(RoutineDetails routineDetails, int position) {
|
||||
// is user checking only today's check
|
||||
|
||||
if (routineDetails.routine_marked == null){
|
||||
/*
|
||||
now, we don't want to allow checking of routine of other day
|
||||
*/
|
||||
try {
|
||||
int today_date = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
|
||||
int selected_date = Integer.parseInt(weekDayViewsList.get(routineViewModel.selected_dow).date.getText().toString());
|
||||
try {
|
||||
int today_date = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
|
||||
int selected_date = Integer.parseInt(weekDayViewsList.get(routineViewModel.selected_dow).date.getText().toString());
|
||||
|
||||
if (today_date == selected_date){
|
||||
AppUtil.showAlert(requireContext(),
|
||||
"Are you sure?",
|
||||
"Do yuo want to check this routine?\nThis cannot be undone.",
|
||||
getString(R.string.yes),
|
||||
(dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
|
||||
updateRoutine(routineDetails, position);
|
||||
|
||||
}, getString(R.string.no),
|
||||
(dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
});
|
||||
}else{
|
||||
Toast.makeText(requireContext(), "Cannot mark future routine.", Toast.LENGTH_SHORT).show();
|
||||
if (today_date == selected_date) {
|
||||
if (routineDetails.routine_marked != null){
|
||||
// already marked
|
||||
return;
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
Toast.makeText(requireContext(), "Couldn't be done.", Toast.LENGTH_SHORT).show();
|
||||
AppUtil.showAlert(requireContext(),
|
||||
"Are you sure?",
|
||||
"Do yuo want to check this routine?\nThis cannot be undone.",
|
||||
getString(R.string.yes),
|
||||
(dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
|
||||
updateRoutine(routineDetails, position);
|
||||
|
||||
}, getString(R.string.no),
|
||||
(dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
});
|
||||
} else {
|
||||
Toast.makeText(requireContext(), "Cannot mark future routine.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(requireContext(), "Couldn't be done.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -223,10 +223,14 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
}
|
||||
|
||||
if (patientData.lat != null && patientData.lng != null) {
|
||||
double lat = Double.parseDouble(patientData.lat);
|
||||
double lng = Double.parseDouble(patientData.lng);
|
||||
try {
|
||||
double lat = Double.parseDouble(patientData.lat);
|
||||
double lng = Double.parseDouble(patientData.lng);
|
||||
|
||||
currentLocation = new LatLng(lat, lng);
|
||||
currentLocation = new LatLng(lat, lng);
|
||||
} catch (NumberFormatException e) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
if (patientData.address_line1 != null) {
|
||||
@@ -389,6 +393,7 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
googleMap.setMyLocationEnabled(true);
|
||||
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
|
||||
}
|
||||
|
||||
requestLocations();
|
||||
}
|
||||
}
|
||||
@@ -409,8 +414,6 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
|
||||
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(default_map_pos));
|
||||
|
||||
addMarker(currentLocation, "Current location");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -422,12 +425,13 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
|
||||
}
|
||||
|
||||
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40.75796541422796, -73.98557368665934), 14));
|
||||
|
||||
googleMap.setOnMapClickListener(this);
|
||||
|
||||
if (currentLocation != null) {
|
||||
addMarker(currentLocation, "Selected location");
|
||||
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLocation, 14));
|
||||
}else{
|
||||
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40.75796541422796, -73.98557368665934), 14));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user