diff --git a/mobile/build.gradle b/mobile/build.gradle index eae6e61..691d9fc 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -24,8 +24,8 @@ android { applicationId "com.thunsaker.rapido" minSdkVersion 14 targetSdkVersion 23 - versionCode 2010 - versionName "2.0.1" + versionCode 2101 + versionName "2.1.01" resConfigs "en", "es" } @@ -81,9 +81,9 @@ dependencies { transitive = true } - compile 'com.android.support:design:23.0.1' - compile 'com.android.support:support-v4:23.0.1' - compile 'com.android.support:appcompat-v7:23.0.1' + compile 'com.android.support:design:23.1.0' + compile 'com.android.support:support-v4:23.1.0' + compile 'com.android.support:appcompat-v7:23.1.0' compile 'com.google.android.gms:play-services-identity:8.1.0' compile 'com.google.android.gms:play-services-plus:8.1.0' compile 'com.google.android.gms:play-services-location:8.1.0' diff --git a/mobile/src/main/AndroidManifest.xml b/mobile/src/main/AndroidManifest.xml index 7f4c47a..aa358a3 100644 --- a/mobile/src/main/AndroidManifest.xml +++ b/mobile/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ diff --git a/mobile/src/main/java/com/thunsaker/rapido/ui/MainFragment.java b/mobile/src/main/java/com/thunsaker/rapido/ui/MainFragment.java index bdb9831..e64bdce 100644 --- a/mobile/src/main/java/com/thunsaker/rapido/ui/MainFragment.java +++ b/mobile/src/main/java/com/thunsaker/rapido/ui/MainFragment.java @@ -1,17 +1,24 @@ package com.thunsaker.rapido.ui; +import android.Manifest; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.app.Activity; +import android.app.AlertDialog; +import android.app.Dialog; import android.app.Notification; import android.app.PendingIntent; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; +import android.content.pm.PackageManager; import android.graphics.Point; import android.location.Location; import android.os.Build; import android.os.Bundle; import android.os.Parcelable; +import android.support.v4.app.ActivityCompat; +import android.support.v4.app.DialogFragment; import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationManagerCompat; import android.support.v4.app.TaskStackBuilder; @@ -164,6 +171,9 @@ public class MainFragment extends BaseRapidoFragment public static final int REQUEST_CODE_LOCATION_PICKER = 4002; public static PickedLocation CurrentPickedLocation; + private static int REQUEST_CODE_PERMISSION_GET_ACCOUNT = 1; + private static int REQUEST_CODE_PERMISSION_ACCESS_FINE_LOCATION = 2; + public final int TWITTER_SHORT_URL_LENGTH = 23; public final int BITLY_SHORT_URL_LENGTH = 20; @@ -184,6 +194,8 @@ public class MainFragment extends BaseRapidoFragment private UpdateEvent mUpdateEventData; private int PLACE_SEARCH_RADIUS = 500; private int PLACE_SEARCH_COUNT = 2; + private String DIALOG_PERM_ACCOUNT_EXPLAINER = "PERM_ACCOUNT_EXPLAINER"; + private String DIALOG_PERM_LOCATION_EXPLAINER = "PERM_LOCATION_EXPLAINER"; // private boolean mLocationEnabled = false; private enum PendingAction { @@ -651,13 +663,12 @@ public void FoursquareChipClick() { // this.getActivity().startActivity(foursquareWebAuth); } } else { - this.getActivity().startActivityForResult(foursquareAuth, REQUEST_CODE_FOURSQUARE_SIGN_IN); + startActivityForResult(foursquareAuth, REQUEST_CODE_FOURSQUARE_SIGN_IN); } } else { UpdateCharCountFromChip(); UpdatePendingUpdateServices(mChipFoursquare, UpdateService.SERVICE_FOURSQUARE); if(CurrentPickedLocation == null) - mButtonLocationAdd.performClick(); ShowLocationPicker(); } } @@ -690,15 +701,46 @@ private void FoursquareSignOut() { public void PlusChipClick() { if(!MainActivity.mPlusEnabled) { mChipPlus.setChecked(false); - this.getActivity().startActivityForResult( - new Intent(mContext, GooglePlusAuthActivity.class), - GooglePlusAuthActivity.REQUEST_CODE_GOOGLE_SIGN_IN); + + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && + ActivityCompat.checkSelfPermission( + getActivity(), + Manifest.permission.GET_ACCOUNTS) + != PackageManager.PERMISSION_GRANTED) { + + if(ActivityCompat.shouldShowRequestPermissionRationale( + getActivity(), + Manifest.permission.GET_ACCOUNTS)) { + PopSnackBar(getString(R.string.perm_get_accounts_rationale), + UpdateService.SERVICE_GOOGLE_PLUS, R.string.perm_enable, + new SnackBar.OnMessageClickListener() { + @Override + public void onMessageClick(Parcelable token) { + ActivityCompat.requestPermissions( + getActivity(), + new String[]{Manifest.permission.GET_ACCOUNTS}, + REQUEST_CODE_PERMISSION_GET_ACCOUNT); + } + }); + } else { + new GooglePlusPermissionExplainerDialog() + .show(getFragmentManager(), DIALOG_PERM_ACCOUNT_EXPLAINER); + } + } else { + startActivityForResult(new Intent(mContext, GooglePlusAuthActivity.class), GooglePlusAuthActivity.REQUEST_CODE_GOOGLE_SIGN_IN); + } } else { UpdateCharCountFromChip(); UpdatePendingUpdateServices(mChipPlus, UpdateService.SERVICE_GOOGLE_PLUS); } } + public void startActivityForResult(Intent intent, int requestCode) { + this.getActivity().startActivityForResult( + intent, + requestCode); + } + @OnLongClick(R.id.compose_to_chip_plus) public boolean PlusChipLongClick() { if(MainActivity.mPlusEnabled) { @@ -731,19 +773,15 @@ private void PlusSignOut() { public void BitlyChipClick() { if(!MainActivity.mBitlyEnabled) { mChipBitly.setChecked(false); - LaunchBitlyAuth(); + startActivityForResult( + new Intent(mContext, BitlyAuthActivity.class), + BitlyAuthActivity.REQUEST_CODE_BITLY_SIGN_IN); } else { UpdateCharCountFromChip(); UpdatePendingUpdateServices(mChipBitly, UpdateService.SERVICE_BITLY); } } - private void LaunchBitlyAuth() { - this.getActivity().startActivityForResult( - new Intent(mContext, BitlyAuthActivity.class), - BitlyAuthActivity.REQUEST_CODE_BITLY_SIGN_IN); - } - @OnLongClick(R.id.compose_to_chip_bitly) public boolean BitlyChipLongClick() { if(MainActivity.mBitlyEnabled) { @@ -783,11 +821,12 @@ private void PopSnackBar(String message, UpdateService service, int actionId, new SnackBar.Builder(this.getActivity()).withMessage(message); if(service != null) { int textColor = ServiceUtils.GetServiceTextColor(service); - int backgroundColor = ServiceUtils.GetServiceColor(service); - SnackBar.Style actionStyle = null; + builder.withTextColorId(textColor); - builder.withTextColorId(textColor) - .withBackgroundColorId(backgroundColor); + if(service != UpdateService.NONE) { + int backgroundColor = ServiceUtils.GetServiceColor(service); + builder.withBackgroundColorId(backgroundColor); + } } if(actionId > 0 && clickListener != null) { @@ -830,7 +869,6 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { mChipFoursquare.setChecked(true); MainActivity.mFoursquareEnabled = mPreferences.foursquareEnabled().getOr(false); - mButtonLocationAdd.performClick(); ShowLocationPicker(); PopSnackBar( @@ -917,11 +955,53 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { } private void ShowLocationPicker() { - startActivityForResult( - new Intent( - mContext, - LocationPicker.class), - REQUEST_CODE_LOCATION_PICKER); + ShowLocationPicker(false, null); + } + + private void ShowLocationPicker(boolean showWave, Point touchPoint) { + Log.i(LOG_TAG, "Inside location picker"); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && + ActivityCompat.checkSelfPermission( + getActivity(), + Manifest.permission.ACCESS_FINE_LOCATION) + != PackageManager.PERMISSION_GRANTED) { + + if(ActivityCompat.shouldShowRequestPermissionRationale( + getActivity(), + Manifest.permission.ACCESS_FINE_LOCATION)) { + PopSnackBar(getString(R.string.perm_location_rationale), + UpdateService.NONE, R.string.perm_enable, + new SnackBar.OnMessageClickListener() { + @Override + public void onMessageClick(Parcelable token) { + ActivityCompat.requestPermissions( + getActivity(), + new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, + REQUEST_CODE_PERMISSION_ACCESS_FINE_LOCATION); + } + }); + } else { + new LocationPermissionExplainerDialog() + .show(getFragmentManager(), DIALOG_PERM_ACCOUNT_EXPLAINER); + } + } else { + if (showWave) { + int color = getResources().getColor(R.color.accent); + WaveCompat.startWaveFilterForResult(this.getActivity(), + new WaveDrawable() + .setColor(color) + .setTouchPoint(touchPoint), + addWaveColorToIntent( + new Intent(mContext, LocationPicker.class), + color), + REQUEST_CODE_LOCATION_PICKER); + } else { + startActivityForResult(new Intent( + mContext, + LocationPicker.class), + REQUEST_CODE_LOCATION_PICKER); + } + } } private void ShowPickedLocationInfo() { @@ -1069,7 +1149,9 @@ public void call(ShortenResponse response) { new SnackBar.OnMessageClickListener() { @Override public void onMessageClick(Parcelable token) { - LaunchBitlyAuth(); + startActivityForResult( + new Intent(mContext, BitlyAuthActivity.class), + BitlyAuthActivity.REQUEST_CODE_BITLY_SIGN_IN); } }); } @@ -1194,7 +1276,7 @@ private void UpdateGooglePlus(String updateText) { .setText(updateText) .getIntent(); - this.startActivityForResult(shareIntent, 0); + startActivityForResult(shareIntent, 0); } } @@ -1528,15 +1610,8 @@ public void ClearPickedLocation() { @Override public void onWaveTouchUp(View view, Point locationInView, Point locationInScreen) { - int color = getResources().getColor(R.color.accent); - WaveCompat.startWaveFilterForResult(this.getActivity(), - new WaveDrawable() - .setColor(color) - .setTouchPoint(locationInScreen), - addWaveColorToIntent( - new Intent(mContext, LocationPicker.class), - color), - REQUEST_CODE_LOCATION_PICKER); + Log.i(LOG_TAG, "Inside onWaveTouchUp"); + ShowLocationPicker(true, locationInScreen); } private Intent addWaveColorToIntent(Intent intent, int color) { @@ -1547,4 +1622,87 @@ private Intent addWaveColorToIntent(Intent intent, int color) { public void setData(UpdateEvent data) { this.mUpdateEventData = data; } + + public void onRequestPermissionsResult(int requestCode, + String[] permissions, + int[] grantResults) { + if(requestCode == REQUEST_CODE_PERMISSION_GET_ACCOUNT) { + Log.i(LOG_TAG, "Inside GET_ACCOUNT Permission response"); + if(grantResults.length == 1 && + grantResults[0] == PackageManager.PERMISSION_GRANTED) { + startActivityForResult( + new Intent(mContext, GooglePlusAuthActivity.class), + GooglePlusAuthActivity.REQUEST_CODE_GOOGLE_SIGN_IN); + } else { + PopSnackBar( + String.format( + getString(R.string.perm_denied), + getString(R.string.perm_get_accounts))); + } + } else if(requestCode == REQUEST_CODE_PERMISSION_ACCESS_FINE_LOCATION) { + Log.i(LOG_TAG, "Inside ACCESS_FINE_LOCATION Permission response"); + if (grantResults.length == 1 && + grantResults[0] == PackageManager.PERMISSION_GRANTED) { + Log.i(LOG_TAG, "Permission Granted, launch LocationPicker"); + mButtonLocationAdd.performClick(); + } else { + Log.i(LOG_TAG, "Else permission denied..."); + PopSnackBar( + String.format( + getString(R.string.perm_denied), + getString(R.string.perm_get_accounts))); + } + } + } + + public static class GooglePlusPermissionExplainerDialog extends DialogFragment { + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + LayoutInflater inflater = getActivity().getLayoutInflater(); + return + new AlertDialog.Builder(this.getActivity()) + .setView(inflater.inflate(R.layout.dialog_permissions_account, null)) + .setPositiveButton(android.R.string.ok, + new DialogInterface.OnClickListener() { + @Override + public void onClick( + DialogInterface dialogInterface, int i) { + ActivityCompat.requestPermissions( + getActivity(), + new String[]{Manifest.permission.GET_ACCOUNTS}, + REQUEST_CODE_PERMISSION_GET_ACCOUNT); + } + }) + .create(); + } + } + + public static class LocationPermissionExplainerDialog extends DialogFragment { + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + LayoutInflater inflater = getActivity().getLayoutInflater(); + return + new AlertDialog.Builder(this.getActivity()) + .setView(inflater.inflate(R.layout.dialog_permissions_location, null)) + .setPositiveButton(R.string.perm_enable, + new DialogInterface.OnClickListener() { + @Override + public void onClick( + DialogInterface dialogInterface, int i) { + ActivityCompat.requestPermissions( + getActivity(), + new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, + REQUEST_CODE_PERMISSION_ACCESS_FINE_LOCATION); + } + }) + .setNegativeButton(android.R.string.cancel, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + // Do Nothing + } + }) + .create(); + } + } } \ No newline at end of file diff --git a/mobile/src/main/res/drawable/permission_header_lock.png b/mobile/src/main/res/drawable/permission_header_lock.png new file mode 100644 index 0000000..0b75af8 Binary files /dev/null and b/mobile/src/main/res/drawable/permission_header_lock.png differ diff --git a/mobile/src/main/res/drawable/permission_header_marker.png b/mobile/src/main/res/drawable/permission_header_marker.png new file mode 100644 index 0000000..aac8d85 Binary files /dev/null and b/mobile/src/main/res/drawable/permission_header_marker.png differ diff --git a/mobile/src/main/res/drawable/rice_green.png b/mobile/src/main/res/drawable/rice_green.png new file mode 100644 index 0000000..ee158d8 Binary files /dev/null and b/mobile/src/main/res/drawable/rice_green.png differ diff --git a/mobile/src/main/res/drawable/rice_green_tiled.xml b/mobile/src/main/res/drawable/rice_green_tiled.xml new file mode 100644 index 0000000..751adfc --- /dev/null +++ b/mobile/src/main/res/drawable/rice_green_tiled.xml @@ -0,0 +1,7 @@ + + \ No newline at end of file diff --git a/mobile/src/main/res/drawable/rice_orange.png b/mobile/src/main/res/drawable/rice_orange.png new file mode 100644 index 0000000..1cfe5c1 Binary files /dev/null and b/mobile/src/main/res/drawable/rice_orange.png differ diff --git a/mobile/src/main/res/drawable/rice_orange_tiled.xml b/mobile/src/main/res/drawable/rice_orange_tiled.xml new file mode 100644 index 0000000..fa20346 --- /dev/null +++ b/mobile/src/main/res/drawable/rice_orange_tiled.xml @@ -0,0 +1,7 @@ + + \ No newline at end of file diff --git a/mobile/src/main/res/drawable/rice_yellow.png b/mobile/src/main/res/drawable/rice_yellow.png new file mode 100644 index 0000000..640a431 Binary files /dev/null and b/mobile/src/main/res/drawable/rice_yellow.png differ diff --git a/mobile/src/main/res/drawable/rice_yellow_tiled.xml b/mobile/src/main/res/drawable/rice_yellow_tiled.xml new file mode 100644 index 0000000..d54df67 --- /dev/null +++ b/mobile/src/main/res/drawable/rice_yellow_tiled.xml @@ -0,0 +1,7 @@ + + \ No newline at end of file diff --git a/mobile/src/main/res/layout/dialog_permissions_account.xml b/mobile/src/main/res/layout/dialog_permissions_account.xml new file mode 100644 index 0000000..655e78f --- /dev/null +++ b/mobile/src/main/res/layout/dialog_permissions_account.xml @@ -0,0 +1,32 @@ + + + + + + + \ No newline at end of file diff --git a/mobile/src/main/res/layout/dialog_permissions_location.xml b/mobile/src/main/res/layout/dialog_permissions_location.xml new file mode 100644 index 0000000..80e00d0 --- /dev/null +++ b/mobile/src/main/res/layout/dialog_permissions_location.xml @@ -0,0 +1,34 @@ + + + + + + + \ No newline at end of file diff --git a/mobile/src/main/res/layout/fragment_compose.xml b/mobile/src/main/res/layout/fragment_compose.xml index 01e71e5..380d5ef 100644 --- a/mobile/src/main/res/layout/fragment_compose.xml +++ b/mobile/src/main/res/layout/fragment_compose.xml @@ -4,231 +4,217 @@ android:layout_height="fill_parent" android:layout_width="match_parent" android:background="?attr/colorPrimary"> - - - - - - - - - - - - - - - - - + android:layout_height="wrap_content"> + - + android:orientation="vertical" + android:background="@color/white"> - - - - - + + + + + + + + - - - - + - - - - - + android:minHeight="150dp"> - + + + - - + android:layout_alignParentLeft="true" + android:layout_alignParentStart="true" + android:layout_toLeftOf="@+id/compose_send_button" + android:layout_toStartOf="@+id/compose_send_button" + android:layout_marginLeft="@dimen/material_keyline_1" + android:layout_marginStart="@dimen/material_keyline_1" + android:layout_marginBottom="@dimen/material_padding" + android:layout_marginTop="@dimen/material_padding" + android:layout_below="@id/compose_edit_text" + android:visibility="gone"> + + + + + + + +