forked from organicmaps/organicmaps
[android] Added bookmark backup controller
This commit is contained in:
parent
ca9068d09f
commit
5bcae10202
5 changed files with 129 additions and 9 deletions
|
@ -39,7 +39,7 @@ public class Authorizer
|
|||
fragment.show(mFragment.getActivity().getSupportFragmentManager(), name);
|
||||
}
|
||||
|
||||
public final void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
public final void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
|
||||
{
|
||||
if (requestCode != Constants.REQ_CODE_GET_SOCIAL_TOKEN
|
||||
|| resultCode != Activity.RESULT_OK || data == null)
|
||||
|
|
|
@ -33,12 +33,12 @@ public class BookmarkCategoriesAdapter extends BaseBookmarkCategoryAdapter<Bookm
|
|||
super(context);
|
||||
}
|
||||
|
||||
public void setOnClickListener(RecyclerClickListener listener)
|
||||
public void setOnClickListener(@Nullable RecyclerClickListener listener)
|
||||
{
|
||||
mClickListener = listener;
|
||||
}
|
||||
|
||||
void setOnLongClickListener(RecyclerLongClickListener listener)
|
||||
void setOnLongClickListener(@Nullable RecyclerLongClickListener listener)
|
||||
{
|
||||
mLongClickListener = listener;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.view.View;
|
|||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.auth.Authorizer;
|
||||
import com.mapswithme.maps.base.BaseMwmRecyclerFragment;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkBackupController;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.dialog.EditTextDialogFragment;
|
||||
|
@ -29,7 +30,7 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
RecyclerClickListener,
|
||||
RecyclerLongClickListener,
|
||||
BookmarkManager.BookmarksLoadingListener,
|
||||
Authorizer.Callback
|
||||
Authorizer.Callback, BookmarkBackupController.BackupListener
|
||||
{
|
||||
private int mSelectedPosition;
|
||||
@Nullable
|
||||
|
@ -38,6 +39,9 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
@NonNull
|
||||
private final Authorizer mAuthorizer = new Authorizer(this, this);
|
||||
|
||||
@Nullable
|
||||
private BookmarkBackupController mBackupController;
|
||||
|
||||
@Override
|
||||
protected @LayoutRes int getLayoutRes()
|
||||
{
|
||||
|
@ -65,6 +69,8 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
mLoadingPlaceholder = view.findViewById(R.id.placeholder_loading);
|
||||
mBackupController = new BookmarkBackupController(view.findViewById(R.id.backup));
|
||||
mBackupController.setListener(this);
|
||||
|
||||
if (getAdapter() != null)
|
||||
{
|
||||
|
@ -234,4 +240,17 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
{
|
||||
// TODO: coming soon.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSignInClick()
|
||||
{
|
||||
mAuthorizer.authorize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
mAuthorizer.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
package com.mapswithme.maps.bookmarks.data;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.widget.BookmarkBackupView;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class BookmarkBackupController
|
||||
{
|
||||
private static final DateFormat DATE_FORMATTER = new SimpleDateFormat("dd.MM.yyyy",
|
||||
Locale.getDefault());
|
||||
@NonNull
|
||||
private final BookmarkBackupView mBackupView;
|
||||
@Nullable
|
||||
private BackupListener mListener;
|
||||
@NonNull
|
||||
private final View.OnClickListener mSignInClickListener = v ->
|
||||
{
|
||||
if (mListener != null)
|
||||
mListener.onSignInClick();
|
||||
};
|
||||
@NonNull
|
||||
private final View.OnClickListener mEnableClickListener = v ->
|
||||
{
|
||||
// TODO: comingsoon
|
||||
};
|
||||
|
||||
|
||||
public BookmarkBackupController(@NonNull BookmarkBackupView backupView)
|
||||
{
|
||||
mBackupView = backupView;
|
||||
update();
|
||||
}
|
||||
|
||||
public void setListener(@Nullable BackupListener listener)
|
||||
{
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
private void update()
|
||||
{
|
||||
final Context context = mBackupView.getContext();
|
||||
boolean isAuthorized = Framework.nativeIsUserAuthenticated();
|
||||
if (!isAuthorized)
|
||||
{
|
||||
mBackupView.setMessage(context.getString(R.string.bookmarks_message_unauthorized_user));
|
||||
mBackupView.setButtonLabel(context.getString(R.string.authorization_button_sign_in));
|
||||
mBackupView.setClickListener(mSignInClickListener);
|
||||
mBackupView.showButton();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isEnabled = false /** TODO: add real call here **/;
|
||||
|
||||
if (isEnabled)
|
||||
{
|
||||
long backupTime = System.currentTimeMillis() /** TODO: use real timestamp here **/;
|
||||
String msg;
|
||||
if (backupTime > 0)
|
||||
{
|
||||
msg = context.getString(R.string.bookmarks_message_backuped_user,
|
||||
DATE_FORMATTER.format(new Date(backupTime)));
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = context.getString(R.string.bookmarks_message_unbackuped_user);
|
||||
}
|
||||
mBackupView.setMessage(msg);
|
||||
mBackupView.hideButton();
|
||||
return;
|
||||
}
|
||||
|
||||
// If backup is disabled.
|
||||
mBackupView.setMessage(context.getString(R.string.bookmarks_message_authorized_user));
|
||||
mBackupView.setButtonLabel(context.getString(R.string.bookmarks_backup));
|
||||
mBackupView.setClickListener(mEnableClickListener);
|
||||
mBackupView.showButton();
|
||||
}
|
||||
|
||||
public interface BackupListener
|
||||
{
|
||||
void onSignInClick();
|
||||
}
|
||||
}
|
|
@ -34,7 +34,7 @@ public class BookmarkBackupView extends LinearLayout
|
|||
@NonNull
|
||||
private final OnClickListener mHeaderClickListener = v -> onHeaderClick();
|
||||
|
||||
private boolean mExpanded = false;
|
||||
private boolean mExpanded = true;
|
||||
|
||||
public BookmarkBackupView(Context context)
|
||||
{
|
||||
|
@ -78,8 +78,7 @@ public class BookmarkBackupView extends LinearLayout
|
|||
@NonNull
|
||||
private Animator createFadeInAnimator()
|
||||
{
|
||||
ObjectAnimator animator = ObjectAnimator.ofFloat(mContentLayout, "alpha",
|
||||
0, 1f);
|
||||
ObjectAnimator animator = ObjectAnimator.ofFloat(mContentLayout, "alpha", 0, 1f);
|
||||
animator.addListener(new AnimatorListenerAdapter()
|
||||
{
|
||||
@Override
|
||||
|
@ -101,8 +100,7 @@ public class BookmarkBackupView extends LinearLayout
|
|||
@NonNull
|
||||
private Animator createFadeOutAnimator()
|
||||
{
|
||||
ObjectAnimator animator = ObjectAnimator.ofFloat(mContentLayout, "alpha",
|
||||
1f, 0);
|
||||
ObjectAnimator animator = ObjectAnimator.ofFloat(mContentLayout, "alpha", 1f, 0);
|
||||
animator.addListener(new AnimatorListenerAdapter()
|
||||
{
|
||||
@Override
|
||||
|
@ -141,6 +139,16 @@ public class BookmarkBackupView extends LinearLayout
|
|||
button.setText(label);
|
||||
}
|
||||
|
||||
public void hideButton()
|
||||
{
|
||||
UiUtils.hide(mContentLayout, R.id.button);
|
||||
}
|
||||
|
||||
public void showButton()
|
||||
{
|
||||
UiUtils.show(mContentLayout, R.id.button);
|
||||
}
|
||||
|
||||
public void setClickListener(@Nullable OnClickListener listener)
|
||||
{
|
||||
mContentLayout.findViewById(R.id.button).setOnClickListener(listener);
|
||||
|
|
Loading…
Add table
Reference in a new issue