Skip to content

Commit 509d29c

Browse files
committed
AC-551: Implemented Dark Mode (Experimental)
1 parent d809cd7 commit 509d29c

61 files changed

Lines changed: 1665 additions & 1496 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

openmrs-client/src/main/AndroidManifest.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
android:name=".activities.visitdashboard.VisitDashboardActivity"
132132
android:label="@string/visit_dashboard_label"
133133
android:launchMode="singleTop"
134-
android:theme="@style/AppTheme">
134+
android:theme="@style/AppThemeOrig">
135135

136136
<!-- Parent activity meta-data to support 4.0 and lower -->
137137
<meta-data
@@ -143,7 +143,7 @@
143143
android:label="@string/action_form_entry"
144144
android:launchMode="singleTop"
145145
android:parentActivityName=".activities.formentrypatientlist.FormEntryPatientListActivity"
146-
android:theme="@style/AppTheme">
146+
android:theme="@style/AppThemeOrig">
147147
<meta-data
148148
android:name="android.support.PARENT_ACTIVITY"
149149
android:value=".activities.formentrypatientlist.FormEntryPatientListActivity" />
@@ -153,7 +153,7 @@
153153
android:configChanges="keyboardHidden|orientation|screenSize"
154154
android:label="@string/action_form_entry"
155155
android:parentActivityName=".activities.dashboard.DashboardActivity"
156-
android:theme="@style/AppTheme">
156+
android:theme="@style/AppThemeOrig">
157157
<meta-data
158158
android:name="android.support.PARENT_ACTIVITY"
159159
android:value=".activities.dashboard.DashboardActivity" />
@@ -163,7 +163,7 @@
163163
android:configChanges="keyboardHidden|orientation|screenSize"
164164
android:label="@string/action_register_patient"
165165
android:parentActivityName=".activities.addeditpatient.AddEditPatientActivity"
166-
android:theme="@style/AppTheme">
166+
android:theme="@style/AppThemeOrig">
167167

168168
<!-- Parent activity meta-data to support 4.0 and lower -->
169169
<meta-data
@@ -188,7 +188,7 @@
188188
android:label="@string/title_activity_form_create"
189189
android:parentActivityName=".activities.formlist.FormListActivity"
190190
android:configChanges="orientation|screenSize|keyboardHidden"
191-
android:theme="@style/AppTheme">
191+
android:theme="@style/AppThemeOrig">
192192
<meta-data
193193
android:name="android.support.PARENT_ACTIVITY"
194194
android:value="org.openmrs.mobile.activities.formlist.FormListActivity" />

openmrs-client/src/main/java/org/openmrs/mobile/activities/ACBaseActivity.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import androidx.annotation.NonNull;
3030
import androidx.appcompat.app.AlertDialog;
3131
import androidx.appcompat.app.AppCompatActivity;
32+
import androidx.appcompat.app.AppCompatDelegate;
3233
import androidx.fragment.app.Fragment;
3334
import androidx.fragment.app.FragmentManager;
3435
import androidx.fragment.app.FragmentTransaction;
@@ -50,6 +51,7 @@
5051
import org.openmrs.mobile.utilities.ApplicationConstants;
5152
import org.openmrs.mobile.utilities.ForceClose;
5253
import org.openmrs.mobile.utilities.NetworkUtils;
54+
import org.openmrs.mobile.utilities.ThemeUtils;
5355
import org.openmrs.mobile.utilities.ToastUtil;
5456

5557
import java.io.File;
@@ -79,6 +81,9 @@ public abstract class ACBaseActivity extends AppCompatActivity {
7981
protected void onCreate(Bundle savedInstanceState) {
8082
super.onCreate(savedInstanceState);
8183
Thread.setDefaultUncaughtExceptionHandler(new ForceClose(this));
84+
85+
setupTheme();
86+
8287
mFragmentManager = getSupportFragmentManager();
8388
mAuthorizationManager = new AuthorizationManager();
8489
locationList = new ArrayList<>();
@@ -383,4 +388,11 @@ public void showAppCrashDialog(String error) {
383388
alertDialog.show();
384389
}
385390

391+
public void setupTheme(){
392+
if(ThemeUtils.isDarkModeActivated()){
393+
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
394+
} else{
395+
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
396+
}
397+
}
386398
}

openmrs-client/src/main/java/org/openmrs/mobile/activities/activevisits/ActiveVisitsRecyclerViewAdapter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.widget.TextView;
2424

2525
import androidx.annotation.NonNull;
26+
import androidx.cardview.widget.CardView;
2627
import androidx.recyclerview.widget.RecyclerView;
2728

2829
import org.openmrs.mobile.R;
@@ -77,7 +78,7 @@ public void onBindViewHolder(@NonNull VisitViewHolder visitViewHolder, final int
7778
visitViewHolder.mBirthDate.setText(" ");
7879
}
7980

80-
visitViewHolder.mRelativeLayout.setOnClickListener(view -> {
81+
visitViewHolder.mLinearLayout.setOnClickListener(view -> {
8182
Intent intent = new Intent(mContext, VisitDashboardActivity.class);
8283
intent.putExtra(ApplicationConstants.BundleKeys.VISIT_ID, mVisits.get(adapterPos).getId());
8384
mContext.startActivity(intent);
@@ -100,11 +101,11 @@ class VisitViewHolder extends RecyclerView.ViewHolder {
100101
private TextView mGender;
101102
private TextView mBirthDate;
102103
private TextView mVisitPlace;
103-
private LinearLayout mRelativeLayout;
104+
private LinearLayout mLinearLayout;
104105

105106
public VisitViewHolder(View itemView) {
106107
super(itemView);
107-
mRelativeLayout = (LinearLayout) itemView;
108+
mLinearLayout = itemView.findViewById(R.id.findVisitContainerLL);
108109
mIdentifier = itemView.findViewById(R.id.findVisitsIdentifier);
109110
mDisplayName = itemView.findViewById(R.id.findVisitsDisplayName);
110111
mVisitPlace = itemView.findViewById(R.id.findVisitsPlace);
@@ -113,7 +114,7 @@ public VisitViewHolder(View itemView) {
113114
}
114115

115116
public void clearAnimation() {
116-
mRelativeLayout.clearAnimation();
117+
mLinearLayout.clearAnimation();
117118
}
118119
}
119120
}

openmrs-client/src/main/java/org/openmrs/mobile/activities/addeditpatient/AddEditPatientActivity.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ protected void onCreate(Bundle savedInstanceState) {
3939
super.onCreate(savedInstanceState);
4040
this.setContentView(R.layout.activity_patient_info);
4141

42-
Toolbar toolbar = findViewById(R.id.toolbar);
43-
44-
if (toolbar != null) {
45-
setSupportActionBar(toolbar);
46-
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
47-
}
48-
4942
// Create fragment
5043
addEditPatientFragment =
5144
(AddEditPatientFragment) getSupportFragmentManager().findFragmentById(R.id.patientInfoContentFrame);

openmrs-client/src/main/java/org/openmrs/mobile/activities/dialog/CustomFragmentDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ private void addSingleChoiceItemsListView(List<String>locationList) {
274274
LinearLayout field = (LinearLayout) mInflater.inflate(R.layout.openmrs_single_choice_list_view, null);
275275
locationListView = field.findViewById(R.id.singleChoiceListView);
276276
locationListView.setAdapter(new ArrayAdapter<>(getActivity(),
277-
android.R.layout.simple_list_item_single_choice, locationList));
277+
R.layout.row_single_checked_layout, locationList));
278278
locationListView.setItemChecked(locationList.indexOf(mOpenMRS.getLocation()),true);
279279
mFieldsLayout.addView(field);
280280

openmrs-client/src/main/java/org/openmrs/mobile/activities/formdisplay/FormDisplayActivity.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ protected void onCreate(Bundle savedInstanceState) {
5353
setContentView(R.layout.activity_form_display);
5454

5555
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
56-
Toolbar toolbar = findViewById(R.id.toolbar);
57-
if (toolbar != null) {
58-
setSupportActionBar(toolbar);
59-
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
60-
}
6156

6257
Bundle bundle = getIntent().getExtras();
6358
String valuereference = null;

openmrs-client/src/main/java/org/openmrs/mobile/activities/formentrypatientlist/FormEntryPatientListActivity.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ public class FormEntryPatientListActivity extends ACBaseActivity {
3232
protected void onCreate(Bundle savedInstanceState) {
3333
super.onCreate(savedInstanceState);
3434
this.setContentView(R.layout.activity_form_entry_patient_list);
35-
Toolbar toolbar = findViewById(R.id.toolbar);
36-
if (toolbar != null) {
37-
setSupportActionBar(toolbar);
38-
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
39-
}
4035

4136
// Create fragment
4237
FormEntryPatientListFragment formEntryPatientListFragment =

openmrs-client/src/main/java/org/openmrs/mobile/activities/formentrypatientlist/FormEntryPatientListAdapter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.widget.TextView;
2323

2424
import androidx.annotation.NonNull;
25+
import androidx.cardview.widget.CardView;
2526
import androidx.recyclerview.widget.RecyclerView;
2627

2728
import org.openmrs.mobile.R;
@@ -99,7 +100,7 @@ public int getItemCount() {
99100
}
100101

101102
class PatientViewHolder extends RecyclerView.ViewHolder {
102-
private LinearLayout mRowLayout;
103+
private CardView mRowLayout;
103104
private TextView mIdentifier;
104105
private TextView mDisplayName;
105106
private TextView mGender;
@@ -110,7 +111,7 @@ class PatientViewHolder extends RecyclerView.ViewHolder {
110111
public PatientViewHolder(View itemView) {
111112
super(itemView);
112113
mVisitStatus = itemView.findViewById(R.id.visitStatusLabel);
113-
mRowLayout = (LinearLayout) itemView;
114+
mRowLayout = (CardView) itemView;
114115
mIdentifier = itemView.findViewById(R.id.syncedPatientIdentifier);
115116
mDisplayName = itemView.findViewById(R.id.syncedPatientDisplayName);
116117
mGender = itemView.findViewById(R.id.syncedPatientGender);

openmrs-client/src/main/java/org/openmrs/mobile/activities/formlist/FormListActivity.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ protected void onCreate(Bundle savedInstanceState) {
3030
super.onCreate(savedInstanceState);
3131
this.setContentView(R.layout.activity_form_list);
3232

33-
Toolbar toolbar = findViewById(R.id.toolbar);
34-
35-
if (toolbar != null) {
36-
setSupportActionBar(toolbar);
37-
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
38-
}
39-
4033
// Create fragment
4134
FormListFragment formListFragment =
4235
(FormListFragment) getSupportFragmentManager().findFragmentById(R.id.formListContentFrame);

openmrs-client/src/main/java/org/openmrs/mobile/activities/patientdashboard/visits/PatientVisitsRecyclerViewAdapter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.widget.TextView;
2323

2424
import androidx.annotation.NonNull;
25+
import androidx.cardview.widget.CardView;
2526
import androidx.recyclerview.widget.RecyclerView;
2627

2728
import org.openmrs.mobile.R;
@@ -73,7 +74,7 @@ public void onBindViewHolder(@NonNull VisitViewHolder visitViewHolder, final int
7374
visitViewHolder.mVisitPlace.setText(mContext.getString(R.string.visit_in, visit.getLocation().getDisplay()));
7475
}
7576

76-
visitViewHolder.mRelativeLayout.setOnClickListener(view -> mContext.goToVisitDashboard(mVisits.get(adapterPos).getId()));
77+
visitViewHolder.mCardView.setOnClickListener(view -> mContext.goToVisitDashboard(mVisits.get(adapterPos).getId()));
7778
}
7879

7980
@Override
@@ -91,19 +92,19 @@ class VisitViewHolder extends RecyclerView.ViewHolder {
9192
private TextView mVisitStart;
9293
private TextView mVisitEnd;
9394
private TextView mVisitStatus;
94-
private RelativeLayout mRelativeLayout;
95+
private CardView mCardView;
9596

9697
public VisitViewHolder(View itemView) {
9798
super(itemView);
98-
mRelativeLayout = (RelativeLayout) itemView;
99+
mCardView = (CardView) itemView;
99100
mVisitStart = itemView.findViewById(R.id.patientVisitStartDate);
100101
mVisitEnd = itemView.findViewById(R.id.patientVisitEndDate);
101102
mVisitPlace = itemView.findViewById(R.id.patientVisitPlace);
102103
mVisitStatus = itemView.findViewById(R.id.visitStatusLabel);
103104
}
104105

105106
public void clearAnimation() {
106-
mRelativeLayout.clearAnimation();
107+
mCardView.clearAnimation();
107108
}
108109
}
109110
}

0 commit comments

Comments
 (0)