Merge improved UI & background task lifecycles #25

Merged
s416204 merged 1 commits from shared-settings-handle-background-task into develop 2018-11-03 11:23:23 +01:00
10 changed files with 70 additions and 55 deletions

View File

@ -8,6 +8,13 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />
<application <application

View File

@ -112,12 +112,25 @@ public abstract class BaseActivity
} }
public void startBackgroundLocalizationTask() { public void startBackgroundLocalizationTask() {
Intent startIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class); if ((ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if ((ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.ACCESS_FINE_LOCATION))) {
startForegroundService(startIntent);
} else {
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION
},
REQUEST_PERMISSIONS);
}
} else { } else {
startService(startIntent);
Intent startIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(startIntent);
} else {
startService(startIntent);
}
} }
} }

View File

@ -117,7 +117,7 @@ public class UsersListFragment extends Fragment {
private void showNoteDialog(final User user) { private void showNoteDialog(final User user) {
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getActivity().getApplicationContext()); LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getActivity().getApplicationContext());
View view = layoutInflaterAndroid.inflate(R.layout.note_dialog, null); View view = layoutInflaterAndroid.inflate(R.layout.user_list_modal, null);
AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(getActivity()); AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(getActivity());
alertDialogBuilderUserInput.setView(view); alertDialogBuilderUserInput.setView(view);
@ -128,6 +128,7 @@ public class UsersListFragment extends Fragment {
TextView userName = view.findViewById(R.id.userName); TextView userName = view.findViewById(R.id.userName);
ListView userDutyHours = view.findViewById(R.id.userDutyHours); ListView userDutyHours = view.findViewById(R.id.userDutyHours);
TextView userDutyHoursTitle = view.findViewById(R.id.userDutyHoursTitle);
TextView userNote = view.findViewById(R.id.userNote); TextView userNote = view.findViewById(R.id.userNote);
TextView userRoom = view.findViewById(R.id.userRoom); TextView userRoom = view.findViewById(R.id.userRoom);
TextView userEmail = view.findViewById(R.id.userEmail); TextView userEmail = view.findViewById(R.id.userEmail);
@ -150,9 +151,10 @@ public class UsersListFragment extends Fragment {
userEmail.setText(String.format("%s: %s", getString(R.string.userEmail), tutorTabViewModel.getEmailTutorTab())); userEmail.setText(String.format("%s: %s", getString(R.string.userEmail), tutorTabViewModel.getEmailTutorTab()));
userNote.setText(String.format("%s: %s", getString(R.string.userNote), tutorTabViewModel.getNote())); userNote.setText(String.format("%s: %s", getString(R.string.userNote), tutorTabViewModel.getNote()));
department.setText(String.format("%s: %s", getString(R.string.userDepartment), user.getDepartment())); department.setText(String.format("%s: %s", getString(R.string.userDepartment), user.getDepartment()));
userDutyHoursTitle.setText(String.format("%s:", getString(R.string.userDutyHoursHeader)));
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity(), final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity(),
android.R.layout.simple_list_item_activated_1, dutyHoursList); android.R.layout.test_list_item, dutyHoursList);
userDutyHours.setAdapter(arrayAdapter); userDutyHours.setAdapter(arrayAdapter);
alertDialog.show(); alertDialog.show();
@ -165,6 +167,7 @@ public class UsersListFragment extends Fragment {
})); }));
} }
private void fetchAllTutors() { private void fetchAllTutors() {
disposable.add( disposable.add(
userService.apiUsersGet() userService.apiUsersGet()

View File

@ -43,14 +43,15 @@ import timber.log.Timber;
public class BackgroundLocalizationService extends Service { public class BackgroundLocalizationService extends Service {
private static final String TAG = "MyLocationService"; private static final String TAG = "MyLocationService";
private static final int LOCATION_INTERVAL = 100; private static final int LOCATION_INTERVAL = 1000;
private static final float LOCATION_DISTANCE = 20f; private static final float LOCATION_DISTANCE = 5f;
public static String str_receiver = "background.location.broadcast"; public static String str_receiver = "background.location.broadcast";
private static long notify_interval = 10000; private static long notify_interval = 10000;
Location mLastLocation; Location mLastLocation;
Intent intent;
ArrayList<String> providers = new ArrayList<String>(); ArrayList<String> providers = new ArrayList<String>();
LocationListener[] mLocationListeners; LocationListener[] mLocationListeners;
private LocationManager mLocationManager = null; private LocationManager mLocationManager = null;
private Handler mHandler = new Handler(); private Handler mHandler = new Handler();
private HandlerThread mHandlerThread = null; private HandlerThread mHandlerThread = null;
@ -59,12 +60,12 @@ public class BackgroundLocalizationService extends Service {
public BackgroundLocalizationService() { public BackgroundLocalizationService() {
providers.add(LocationManager.GPS_PROVIDER); providers.add(LocationManager.GPS_PROVIDER);
providers.add(LocationManager.NETWORK_PROVIDER); providers.add(LocationManager.NETWORK_PROVIDER);
//providers.add(LocationManager.PASSIVE_PROVIDER); providers.add(LocationManager.PASSIVE_PROVIDER);
mLocationListeners = new LocationListener[]{ mLocationListeners = new LocationListener[]{
new LocationListener(LocationManager.GPS_PROVIDER), new LocationListener(LocationManager.GPS_PROVIDER),
new LocationListener(LocationManager.NETWORK_PROVIDER) new LocationListener(LocationManager.NETWORK_PROVIDER),
//new LocationListener(LocationManager.PASSIVE_PROVIDER) new LocationListener(LocationManager.PASSIVE_PROVIDER)
}; };
} }
@ -175,15 +176,17 @@ public class BackgroundLocalizationService extends Service {
List<String> providers1 = mLocationManager.getProviders(true); List<String> providers1 = mLocationManager.getProviders(true);
Location bestLocation = null; Location bestLocation = null;
for (String provider : providers1) { for (String provider : providers1) {
Location location = mLocationManager.getLastKnownLocation(provider); Location location = mLocationManager.getLastKnownLocation(provider);
Log.e("Location", String.valueOf(location));
if (location == null) { if (location == null) {
continue; continue;
} }
if (bestLocation == null || location.getAccuracy() < bestLocation.getAccuracy()) { if (bestLocation == null || location.getAccuracy() < bestLocation.getAccuracy()) {
bestLocation = location; bestLocation = location;
} }
} }
Log.e("Best localization:", String.valueOf(bestLocation)); Log.e("Best localization:", String.valueOf(bestLocation));

View File

@ -61,7 +61,7 @@ public class MyDividerItemDecoration extends RecyclerView.ItemDecoration {
.getLayoutParams(); .getLayoutParams();
final int top = child.getBottom() + params.bottomMargin; final int top = child.getBottom() + params.bottomMargin;
final int bottom = top + mDivider.getIntrinsicHeight(); final int bottom = top + mDivider.getIntrinsicHeight();
mDivider.setBounds(left + dpToPx(margin), top, right - dpToPx(margin), bottom); mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c); mDivider.draw(c);
} }
} }

View File

@ -12,13 +12,12 @@
android:paddingTop="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".activity.LoginActivity"> tools:context=".activity.LoginActivity">
<!-- Login progress -->
<ImageView <ImageView
android:id="@+id/imageView" android:id="@+id/imageView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="180dp" android:layout_height="180dp"
android:contentDescription="Logo find my tutor" android:contentDescription="@string/logo_find_my_tutor"
app:srcCompat="@drawable/logo_design_black2" /> app:srcCompat="@drawable/logo_design_black2" />
<ProgressBar <ProgressBar
@ -48,7 +47,7 @@
android:id="@+id/email" android:id="@+id/email"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/prompt_email" android:hint="@string/prompt_login"
android:inputType="textEmailAddress" android:inputType="textEmailAddress"
android:maxLines="1" android:maxLines="1"
android:singleLine="true" /> android:singleLine="true" />
@ -85,11 +84,10 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:text="@string/action_sign_in" android:text="@string/action_log_in"
android:textStyle="bold" /> android:textStyle="bold" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
</LinearLayout> </LinearLayout>

View File

@ -1,24 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:id="@+id/image_view"
android:layout_width="0dp"
android:layout_height="75dp"
android:layout_weight="30"
android:contentDescription="@string/app_name" />
<TextView
android:id="@+id/text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="70"
android:gravity="center"
android:text=""
android:textStyle="bold" />
</LinearLayout>

View File

@ -4,9 +4,9 @@
android:layout_height="90dp" android:layout_height="90dp"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:paddingLeft="@dimen/activity_margin" android:paddingLeft="10dp"
android:paddingTop="@dimen/dimen_10" android:paddingTop="@dimen/dimen_10"
android:paddingRight="@dimen/activity_margin" android:paddingRight="10dp"
android:paddingBottom="@dimen/dimen_10"> android:paddingBottom="@dimen/dimen_10">

View File

@ -15,7 +15,7 @@
android:fontFamily="sans-serif-medium" android:fontFamily="sans-serif-medium"
android:lineSpacingExtra="8sp" android:lineSpacingExtra="8sp"
android:text="@string/lbl_new_note_title" android:text="@string/lbl_new_note_title"
android:textColor="@color/note_list_text" android:textColor="@color/colorAccent"
android:textSize="@dimen/lbl_new_note_title" android:textSize="@dimen/lbl_new_note_title"
android:textStyle="normal" /> android:textStyle="normal" />
@ -23,6 +23,8 @@
android:id="@+id/userDepartment" android:id="@+id/userDepartment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:lineSpacingExtra="8sp"
android:paddingTop="5dp"
android:textColor="@color/note_list_text" android:textColor="@color/note_list_text"
/> />
@ -30,6 +32,8 @@
android:id="@+id/userRoom" android:id="@+id/userRoom"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:lineSpacingExtra="8sp"
android:paddingTop="5dp"
android:textColor="@color/note_list_text" android:textColor="@color/note_list_text"
/> />
@ -37,13 +41,16 @@
android:id="@+id/userEmail" android:id="@+id/userEmail"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:lineSpacingExtra="8sp"
android:paddingTop="5dp"
android:textColor="@color/note_list_text" /> android:textColor="@color/note_list_text" />
<TextView <TextView
android:id="@+id/userDutyHoursTitle" android:id="@+id/userDutyHoursTitle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/userDutyHoursHeader" android:lineSpacingExtra="8sp"
android:paddingTop="5dp"
android:textColor="@color/note_list_text" android:textColor="@color/note_list_text"
tools:text="@string/dutyHours" /> tools:text="@string/dutyHours" />
@ -51,12 +58,17 @@
android:id="@+id/userDutyHours" android:id="@+id/userDutyHours"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="@color/note_list_text" /> android:paddingTop="0dp"
android:paddingBottom="0dp"
android:paddingStart="@dimen/activity_margin"
android:textColor="@color/colorAccent" />
<TextView <TextView
android:id="@+id/userNote" android:id="@+id/userNote"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:lineSpacingExtra="8sp"
android:paddingTop="5dp"
android:textColor="@color/note_list_text" /> android:textColor="@color/note_list_text" />
</LinearLayout> </LinearLayout>

View File

@ -1,7 +1,7 @@
<resources> <resources>
<string name="app_name" translatable="false">FindMyTutor</string> <string name="app_name" translatable="false">FindMyTutor</string>
<string name="title_activity_login">Sign in</string> <string name="title_activity_login">Sign in</string>
<string name="title_activity_startup" translatable="false">StartUp Activity</string> <string name="title_activity_startup" translatable="false">Find My Tutor</string>
<!-- Menu --> <!-- Menu -->
<string name="nav_map">Map</string> <string name="nav_map">Map</string>
@ -26,7 +26,7 @@
<!-- Strings related to login --> <!-- Strings related to login -->
<string name="prompt_email" translatable="false">Email</string> <string name="prompt_email" translatable="false">Email</string>
<string name="prompt_password">Password (optional)</string> <string name="prompt_password">Password</string>
<string name="action_sign_in">Sign in or register</string> <string name="action_sign_in">Sign in or register</string>
<string name="action_sign_out">Sign out</string> <string name="action_sign_out">Sign out</string>
<string name="action_sign_in_short">Sign in</string> <string name="action_sign_in_short">Sign in</string>
@ -204,13 +204,16 @@ functionality.</string>
<string name="there_is_no_users_in_system">There is no users in system</string> <string name="there_is_no_users_in_system">There is no users in system</string>
<string name="cancel">Close</string> <string name="cancel">Close</string>
<string name="userRoom">Pokój</string> <string name="userRoom"><b>Pokój</b></string>
<string name="userEmail">Email</string> <string name="userEmail"><b>Email</b></string>
<string name="userNote">Notatka</string> <string name="userNote"><b>Notatka</b></string>
<string name="userDutyHoursHeader">Dyżury</string> <string name="userDutyHoursHeader"><b>Dyżury</b></string>
<string name="dutyHours">Dyżury</string> <string name="dutyHours"> <b>Dyżury</b></string>
<string name="error_invalid_login_name">Invalid format login. Use s11111 format</string> <string name="error_invalid_login_name">Invalid format login. Use s11111 format</string>
<string name="userDepartment">Zakład</string> <string name="userDepartment">Zakład</string>
<string name="loading">Loading ...</string> <string name="loading">Loading ...</string>
<string name="logo_find_my_tutor">Logo find my tutor</string>
<string name="prompt_login">Login (sXXXXXX)</string>
<string name="action_log_in">Log in </string>
</resources> </resources>