[android] review fixes

This commit is contained in:
Roman Romanov 2017-06-02 07:55:47 +04:00
parent 8a6eee94f8
commit ee1e8df091
24 changed files with 54 additions and 86 deletions

View file

@ -116,10 +116,4 @@ extern "C"
frm()->SaveTransliteration(value);
frm()->AllowTransliteration(value);
}
JNIEXPORT void JNICALL
Java_com_mapswithme_util_Config_nativeReload(JNIEnv * env, jclass thiz)
{
settings::Reload();
}
} // extern "C"

View file

Before

Width:  |  Height:  |  Size: 557 B

After

Width:  |  Height:  |  Size: 557 B

View file

Before

Width:  |  Height:  |  Size: 205 B

After

Width:  |  Height:  |  Size: 205 B

View file

Before

Width:  |  Height:  |  Size: 381 B

After

Width:  |  Height:  |  Size: 381 B

View file

Before

Width:  |  Height:  |  Size: 149 B

After

Width:  |  Height:  |  Size: 149 B

View file

Before

Width:  |  Height:  |  Size: 734 B

After

Width:  |  Height:  |  Size: 734 B

View file

Before

Width:  |  Height:  |  Size: 223 B

After

Width:  |  Height:  |  Size: 223 B

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

Before

Width:  |  Height:  |  Size: 353 B

After

Width:  |  Height:  |  Size: 353 B

View file

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

Before

Width:  |  Height:  |  Size: 489 B

After

Width:  |  Height:  |  Size: 489 B

View file

@ -9,7 +9,7 @@
</shape>
</item>
<item
android:drawable="@drawable/ic_navigation_light_24_px"
android:drawable="@drawable/ic_navigation_light"
android:left="@dimen/margin_half"
android:right="@dimen/margin_half"
android:top="@dimen/margin_half"

View file

@ -9,7 +9,7 @@
</shape>
</item>
<item
android:drawable="@drawable/ic_storage_light_24_px"
android:drawable="@drawable/ic_storage_light"
android:left="@dimen/margin_half"
android:right="@dimen/margin_half"
android:top="@dimen/margin_half"

View file

@ -182,6 +182,7 @@ public class MapFragment extends BaseMwmFragment
public void run()
{
LocationHelper.INSTANCE.onExitFromFirstRun();
Framework.nativeRunFirstLaunchAnimation();
}
});
}

View file

@ -95,6 +95,7 @@ import com.mapswithme.util.ThemeUtils;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Utils;
import com.mapswithme.util.concurrency.UiThread;
import com.mapswithme.util.permissions.PermissionsResult;
import com.mapswithme.util.sharing.ShareOption;
import com.mapswithme.util.sharing.SharingHelper;
import com.mapswithme.util.statistics.AlohaHelper;
@ -193,16 +194,13 @@ public class MwmActivity extends BaseMwmFragmentActivity
Statistics.INSTANCE.trackEvent(Statistics.EventName.TOOLBAR_MY_POSITION);
AlohaHelper.logClick(AlohaHelper.TOOLBAR_MY_POSITION);
boolean granted = PermissionsUtils.isLocationGranted();
if (!granted && PermissionsUtils.isLocationExplanationNeeded(MwmActivity.this))
if (!PermissionsUtils.isLocationGranted())
{
PermissionsUtils.requestLocationPermission(MwmActivity.this, LOCATION_REQUEST);
return;
}
else if (!granted)
{
Toast.makeText(MwmActivity.this, R.string.location_permission_denied, Toast.LENGTH_SHORT)
.show();
if (PermissionsUtils.isLocationExplanationNeeded(MwmActivity.this))
PermissionsUtils.requestLocationPermission(MwmActivity.this, LOCATION_REQUEST);
else
Toast.makeText(MwmActivity.this, R.string.location_permission_denied, Toast.LENGTH_SHORT)
.show();
return;
}
@ -992,7 +990,8 @@ public class MwmActivity extends BaseMwmFragmentActivity
if (requestCode != LOCATION_REQUEST || grantResults.length == 0)
return;
if (PermissionsUtils.computePermissionsResult(permissions, grantResults).isLocationGranted())
PermissionsResult result = PermissionsUtils.computePermissionsResult(permissions, grantResults);
if (result.isLocationGranted())
myPositionClick();
}

View file

@ -43,18 +43,13 @@ public class SplashActivity extends AppCompatActivity
private boolean mNeedStoragePermission;
private boolean mCanceled;
@Nullable
private DialogFragment mPermissionsDialog;
@Nullable
private DialogFragment mStoragePermissionsDialog;
@NonNull
private final Runnable mPermissionsTask = new Runnable()
{
@Override
public void run()
{
mPermissionsDialog = PermissionsDialogFragment.show(SplashActivity.this, REQUEST_PERMISSIONS);
PermissionsDialogFragment.show(SplashActivity.this, REQUEST_PERMISSIONS);
}
};
@ -113,39 +108,30 @@ public class SplashActivity extends AppCompatActivity
super.onResume();
mCanceled = false;
mPermissionsGranted = PermissionsUtils.isExternalStorageGranted();
DialogFragment storagePermissionsDialog = StoragePermissionsDialogFragment.find(this);
DialogFragment permissionsDialog = PermissionsDialogFragment.find(this);
if (!mPermissionsGranted)
{
mStoragePermissionsDialog = StoragePermissionsDialogFragment.find(this);
if (mNeedStoragePermission || mStoragePermissionsDialog != null)
if (mNeedStoragePermission || storagePermissionsDialog != null)
{
if (mPermissionsDialog != null)
{
mPermissionsDialog.dismiss();
mPermissionsDialog = null;
}
if (mStoragePermissionsDialog == null)
mStoragePermissionsDialog = StoragePermissionsDialogFragment.show(this);
if (permissionsDialog != null)
permissionsDialog.dismiss();
if (storagePermissionsDialog == null)
StoragePermissionsDialogFragment.show(this);
return;
}
mPermissionsDialog = PermissionsDialogFragment.find(this);
if (mPermissionsDialog == null)
permissionsDialog = PermissionsDialogFragment.find(this);
if (permissionsDialog == null)
UiThread.runLater(mPermissionsTask, FIRST_START_DELAY);
return;
}
else
{
if (mPermissionsDialog != null)
{
mPermissionsDialog.dismiss();
mPermissionsDialog = null;
}
if (mStoragePermissionsDialog != null)
{
mStoragePermissionsDialog.dismiss();
mStoragePermissionsDialog = null;
}
}
if (permissionsDialog != null)
permissionsDialog.dismiss();
if (storagePermissionsDialog != null)
storagePermissionsDialog.dismiss();
UiThread.runLater(mDelayedTask, DELAY);
}

View file

@ -5,6 +5,7 @@ import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.support.v4.app.DialogFragment;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import com.mapswithme.util.ThemeUtils;
@ -12,6 +13,9 @@ public class BaseMwmDialogFragment extends DialogFragment
{
protected final @StyleRes int getFullscreenTheme()
{
if (!MwmApplication.get().isPlatformInitialized())
return R.style.MwmTheme_DialogFragment_Fullscreen;
return (ThemeUtils.isNightTheme() ? R.style.MwmTheme_DialogFragment_Fullscreen_Night
: R.style.MwmTheme_DialogFragment_Fullscreen);
}

View file

@ -20,11 +20,15 @@ import android.widget.TextView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmDialogFragment;
import com.mapswithme.util.PermissionsUtils;
import com.mapswithme.util.log.Logger;
import com.mapswithme.util.log.LoggerFactory;
abstract class BasePermissionsDialogFragment extends BaseMwmDialogFragment
implements View.OnClickListener
{
private static final String REQUEST_ID = "arg_request_id";
private static final String TAG = BasePermissionsDialogFragment.class.getName();
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
private static final String ARG_REQUEST_ID = "arg_request_id";
private int mRequestId;
@ -46,21 +50,20 @@ abstract class BasePermissionsDialogFragment extends BaseMwmDialogFragment
{
dialog = dialogClass.newInstance();
final Bundle args = new Bundle();
args.putInt(REQUEST_ID, requestId);
args.putInt(ARG_REQUEST_ID, requestId);
dialog.setArguments(args);
dialog.setCancelable(false);
dialog.show(fm, dialogClass.getName());
}
catch (java.lang.InstantiationException e)
{
e.printStackTrace();
LOGGER.e(TAG, "Can't instantiate " + dialogClass.getName() + " fragment", e);
}
catch (IllegalAccessException e)
{
e.printStackTrace();
LOGGER.e(TAG, "Can't instantiate " + dialogClass.getName() + " fragment", e);
}
return dialog;
}
@ -70,9 +73,7 @@ abstract class BasePermissionsDialogFragment extends BaseMwmDialogFragment
super.onCreate(savedInstanceState);
Bundle args = getArguments();
if (args != null)
{
mRequestId = args.getInt(REQUEST_ID);
}
mRequestId = args.getInt(ARG_REQUEST_ID);
}
@Override

View file

@ -16,6 +16,7 @@ import com.mapswithme.maps.R;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class PermissionsAdapter extends RecyclerView.Adapter<PermissionsAdapter.ViewHolder>
@ -30,18 +31,19 @@ class PermissionsAdapter extends RecyclerView.Adapter<PermissionsAdapter.ViewHol
private static final List<PermissionItem> ITEMS;
static {
ITEMS = new ArrayList<>();
ITEMS.add(new PermissionItem(TYPE_TITLE, R.string.onboarding_detail_permissions_title, 0, 0));
ITEMS.add(new PermissionItem(TYPE_PERMISSION,
ArrayList<PermissionItem> items = new ArrayList<>();
items.add(new PermissionItem(TYPE_TITLE, R.string.onboarding_detail_permissions_title, 0, 0));
items.add(new PermissionItem(TYPE_PERMISSION,
R.string.onboarding_detail_permissions_storage_title,
R.string.onboarding_detail_permissions_storage_message,
R.drawable.ic_storage_permission));
ITEMS.add(new PermissionItem(TYPE_PERMISSION,
items.add(new PermissionItem(TYPE_PERMISSION,
R.string.onboarding_detail_permissions_location_title,
R.string.onboarding_detail_permissions_location_message,
R.drawable.ic_navigation_permission));
ITEMS.add(new PermissionItem(TYPE_NOTE, 0,
items.add(new PermissionItem(TYPE_NOTE, 0,
R.string.onboarding_detail_permissions_storage_path_message, 0));
ITEMS = Collections.unmodifiableList(items);
}
@ViewHolderType
@ -106,7 +108,7 @@ class PermissionsAdapter extends RecyclerView.Adapter<PermissionsAdapter.ViewHol
static abstract class ViewHolder extends RecyclerView.ViewHolder
{
public ViewHolder(View itemView)
public ViewHolder(@NonNull View itemView)
{
super(itemView);
}
@ -118,7 +120,7 @@ class PermissionsAdapter extends RecyclerView.Adapter<PermissionsAdapter.ViewHol
{
private final TextView mTitle;
TitleViewHolder(View itemView)
TitleViewHolder(@NonNull View itemView)
{
super(itemView);
@ -138,7 +140,7 @@ class PermissionsAdapter extends RecyclerView.Adapter<PermissionsAdapter.ViewHol
private final TextView mTitle;
private final TextView mMessage;
PermissionViewHolder(View itemView)
PermissionViewHolder(@NonNull View itemView)
{
super(itemView);
mIcon = (ImageView) itemView.findViewById(R.id.iv__permission_icon);
@ -159,7 +161,7 @@ class PermissionsAdapter extends RecyclerView.Adapter<PermissionsAdapter.ViewHol
{
private final TextView mMessage;
NoteViewHolder(View itemView)
NoteViewHolder(@NonNull View itemView)
{
super(itemView);
mMessage = (TextView) itemView.findViewById(R.id.tv__note);

View file

@ -105,7 +105,6 @@ public final class Config
public static void migrateCountersToSharedPrefs()
{
nativeReload();
int version = getInt(KEY_APP_FIRST_INSTALL_VERSION, BuildConfig.VERSION_CODE);
MwmApplication.prefs()
.edit()
@ -336,5 +335,4 @@ public final class Config
private static native void nativeSetLargeFontsSize(boolean value);
private static native boolean nativeGetTransliteration();
private static native void nativeSetTransliteration(boolean value);
private static native void nativeReload();
}

View file

@ -25,11 +25,9 @@ char const * kMeasurementUnits = "Units";
StringStorage::StringStorage() : StringStorageBase(GetPlatform().SettingsPathForFile(SETTINGS_FILE_NAME)) {}
StringStorage & StringStorage::Instance(bool reload)
StringStorage & StringStorage::Instance()
{
static StringStorage inst;
if (reload)
inst = StringStorage();
return inst;
}

View file

@ -21,7 +21,7 @@ string ToString(T const & value);
class StringStorage : public platform::StringStorageBase
{
public:
static StringStorage & Instance(bool reload = false);
static StringStorage & Instance();
private:
StringStorage();
@ -42,7 +42,6 @@ void Set(string const & key, Value const & value)
StringStorage::Instance().SetValue(key, ToString(value));
}
inline void Reload() { StringStorage::Instance(true); }
inline void Delete(string const & key) { StringStorage::Instance().DeleteKeyAndValue(key); }
inline void Clear() { StringStorage::Instance().Clear(); }

View file

@ -49,17 +49,6 @@ StringStorageBase::StringStorageBase(string const & path) : m_path(path)
}
}
StringStorageBase::StringStorageBase(StringStorageBase const & rhs)
{
m_values = Container(rhs.m_values.begin(), rhs.m_values.end());
}
StringStorageBase& StringStorageBase::operator=(StringStorageBase const & rhs)
{
m_values = Container(rhs.m_values.begin(), rhs.m_values.end());
return *this;
}
void StringStorageBase::Save() const
{
try

View file

@ -10,14 +10,11 @@ class StringStorageBase
{
public:
StringStorageBase(std::string const & path);
StringStorageBase(StringStorageBase const & rhs);
void Save() const;
void Clear();
bool GetValue(std::string const & key, std::string & outValue) const;
void SetValue(std::string const & key, std::string && value);
void DeleteKeyAndValue(std::string const & key);
StringStorageBase& operator=(StringStorageBase const & rhs);
private:
using Container = std::map<std::string, std::string>;