Skip to content

Commit

Permalink
AC-618: Revamp Settings Page
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak140596 committed Jun 9, 2019
1 parent b45b731 commit cf97ba4
Show file tree
Hide file tree
Showing 19 changed files with 277 additions and 238 deletions.
1 change: 1 addition & 0 deletions openmrs-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ dependencies {
implementation "androidx.gridlayout:gridlayout:$support_version"
implementation "androidx.recyclerview:recyclerview:$support_version"
implementation "androidx.cardview:cardview:$support_version"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "com.google.android.material:material:$support_version"
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
Expand Down
Binary file added openmrs-client/src/main/ic_privacy_policy-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ interface View extends BaseView<Presenter> {

void addLogsInfo(long logSize, String logFilename);

void setUpConceptsView();

void setConceptsInDbText(String text);

void addBuildVersionInfo();

void addPrivacyPolicyInfo();

void applyChanges();
void rateUs();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,40 @@
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import org.openmrs.mobile.R;
import org.openmrs.mobile.activities.ACBaseFragment;
import org.openmrs.mobile.models.SettingsListItemDTO;
import org.openmrs.mobile.activities.logs.LogsActivity;
import org.openmrs.mobile.services.ConceptDownloadService;
import org.openmrs.mobile.utilities.ApplicationConstants;
import org.openmrs.mobile.utilities.ToastUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import androidx.annotation.NonNull;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class SettingsFragment extends ACBaseFragment<SettingsContract.Presenter> implements SettingsContract.View {

private List<SettingsListItemDTO> mListItem = new ArrayList<>();
private RecyclerView settingsRecyclerView;

private BroadcastReceiver bReceiver;

private TextView conceptsInDbTextView;
private ImageButton downloadConceptsButton;

private View root;

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_settings, container, false);
root = inflater.inflate(R.layout.fragment_settings, container, false);

bReceiver = new BroadcastReceiver() {
@Override
Expand All @@ -67,29 +63,13 @@ public void onReceive(Context context, Intent intent) {
}
};

settingsRecyclerView = (RecyclerView) root.findViewById(R.id.settingsRecyclerView);
settingsRecyclerView.setHasFixedSize(true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
settingsRecyclerView.setLayoutManager(linearLayoutManager);

conceptsInDbTextView = ((TextView) root.findViewById(R.id.conceptsInDbTextView));

downloadConceptsButton = ((ImageButton) root.findViewById(R.id.downloadConceptsButton));

downloadConceptsButton.setOnClickListener(view -> {
downloadConceptsButton.setEnabled(false);
Intent startIntent = new Intent(getActivity(), ConceptDownloadService.class);
startIntent.setAction(ApplicationConstants.ServiceActions.START_CONCEPT_DOWNLOAD_ACTION);
Objects.requireNonNull(getActivity()).startService(startIntent);
});

setUpConceptsView();
return root;
}

@Override
public void onPause() {
super.onPause();
mListItem = new ArrayList<>();
LocalBroadcastManager.getInstance(this.getActivity()).unregisterReceiver(bReceiver);
}

Expand All @@ -113,9 +93,30 @@ public void setConceptsInDbText(String text) {

@Override
public void addLogsInfo(long logSize, String logFilename) {
mListItem.add(new SettingsListItemDTO(getResources().getString(R.string.settings_logs),
logFilename,
"Size: " + logSize + "kB"));
LinearLayout logsLl = root.findViewById(R.id.frag_settings_logs_ll);
TextView logsDesc1Tv = root.findViewById(R.id.frag_settings_logs_desc1_tv);
TextView logsDesc2Tv = root.findViewById(R.id.frag_settings_logs_desc2_tv);

logsDesc1Tv.setText(logFilename);
logsDesc2Tv.setText(getContext().getString(R.string.settings_frag_size) + logSize + "kB");
logsLl.setOnClickListener(view ->{
Intent i = new Intent(view.getContext() , LogsActivity.class);
startActivity(i);
});
}

@Override
public void setUpConceptsView() {
conceptsInDbTextView = root.findViewById(R.id.frag_settings_concepts_count_tv);

downloadConceptsButton = root.findViewById(R.id.frag_settings_concepts_download_btn);

downloadConceptsButton.setOnClickListener(view -> {
downloadConceptsButton.setEnabled(false);
Intent startIntent = new Intent(getActivity(), ConceptDownloadService.class);
startIntent.setAction(ApplicationConstants.ServiceActions.START_CONCEPT_DOWNLOAD_ACTION);
Objects.requireNonNull(getActivity()).startService(startIntent);
});
}

@Override
Expand All @@ -136,20 +137,28 @@ public void addBuildVersionInfo() {
mPresenter.logException("Failed to load meta-data, NullPointer: " + e.getMessage());
}

mListItem.add(new SettingsListItemDTO(getResources().getString(R.string.settings_about),
getResources().getString(R.string.app_name),
versionName + " Build: " + buildVersion));
TextView appName = root.findViewById(R.id.frag_settings_app_name_tv);
TextView version = root.findViewById(R.id.frag_settings_version_tv);

appName.setText(getResources().getString(R.string.app_name));
version.setText(versionName + getContext().getString(R.string.frag_settings_build) + buildVersion);
}

@Override
public void addPrivacyPolicyInfo() {
mListItem.add(new SettingsListItemDTO(getString(R.string.settings_privacy_policy)));
LinearLayout privacyPolicyTv = root.findViewById(R.id.frag_settings_privacy_policy_ll);
privacyPolicyTv.setOnClickListener(view ->{
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(view.getContext().getString(R.string.url_privacy_policy)));
startActivity(i);
});
}

@Override
public void applyChanges() {
SettingsRecyclerViewAdapter adapter = new SettingsRecyclerViewAdapter(mListItem);
settingsRecyclerView.setAdapter(adapter);
public void rateUs() {
LinearLayout rateUsLL = root.findViewById(R.id.frag_settings_rate_us_ll);
rateUsLL.setOnClickListener(v -> startActivity(new Intent(Intent.ACTION_VIEW, Uri
.parse("market://details?id=" + ApplicationConstants.PACKAGE_NAME))));
}

public static SettingsFragment newInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public SettingsPresenter(@NonNull SettingsContract.View view, @NonNull OpenMRSLo

@Override
public void subscribe() {
fillList();
updateViews();
mSettingsView.setConceptsInDbText(String.valueOf(conceptDAO.getConceptsCount()));
}

private void fillList() {
private void updateViews() {
long size = 0;
String filename = OpenMRS.getInstance().getOpenMRSDir()
+ File.separator + mOpenMRSLogger.getLogFilename();
Expand All @@ -70,7 +70,7 @@ private void fillList() {
mSettingsView.addLogsInfo(size, filename);
mSettingsView.addBuildVersionInfo();
mSettingsView.addPrivacyPolicyInfo();
mSettingsView.applyChanges();
mSettingsView.rateUs();
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public abstract class ApplicationConstants {
public static final String DB_PASSWORD_LITERAL_PEPPER = "Open Sesame";
public static final String DEFAULT_VISIT_TYPE_UUID = "7b0f5697-27e3-40c4-8bae-f4049abfb4ed";
public static final int DEFAULT_BCRYPT_ROUND = 8;
public static final String PACKAGE_NAME = "org.openmrs.mobile";

public abstract static class OpenMRSSharedPreferenceNames {
public static final String SHARED_PREFERENCES_NAME = "shared_preferences";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="?android:colorControlNormal"
android:pathData="M12,21.35l-1.45,-1.32C5.4,15.36 2,12.28 2,8.5 2,5.42 4.42,3 7.5,3c1.74,0 3.41,0.81 4.5,2.09C13.09,3.81 14.76,3 16.5,3 19.58,3 22,5.42 22,8.5c0,3.78 -3.4,6.86 -8.55,11.54L12,21.35z"/>
</vector>
11 changes: 11 additions & 0 deletions openmrs-client/src/main/res/drawable/ic_favorite_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="?android:colorControlNormal"
android:pathData="M12,21.35l-1.45,-1.32C5.4,15.36 2,12.28 2,8.5 2,5.42 4.42,3 7.5,3c1.74,0 3.41,0.81 4.5,2.09C13.09,3.81 14.76,3 16.5,3 19.58,3 22,5.42 22,8.5c0,3.78 -3.4,6.86 -8.55,11.54L12,21.35z"
tools:targetApi="lollipop" />
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M19,9h-4V3H9v6H5l7,7 7,-7zM5,18v2h14v-2H5z"/>
</vector>
Loading

0 comments on commit cf97ba4

Please sign in to comment.