forked from organicmaps/organicmaps
[android] Added progress dialog for uploading, added a little bit upload process supporting
This commit is contained in:
parent
a2c084d74a
commit
0dbabdb791
6 changed files with 309 additions and 3 deletions
26
android/res/layout/indeterminated_progress_dialog.xml
Normal file
26
android/res/layout/indeterminated_progress_dialog.xml
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<LinearLayout
|
||||
android:id="@+id/body"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:baselineAligned="false"
|
||||
android:padding="16dip">
|
||||
<ProgressBar
|
||||
android:id="@android:id/progress"
|
||||
style="?android:attr/progressBarStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dip"
|
||||
android:layout_marginRight="16dip"/>
|
||||
<TextView
|
||||
android:id="@+id/message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"/>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
|
@ -0,0 +1,8 @@
|
|||
<?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:id="@+id/fragment_container"
|
||||
android:orientation="vertical">
|
||||
</LinearLayout>
|
|
@ -567,6 +567,11 @@ public enum BookmarkManager
|
|||
nativeImportFromCatalog(serverId, filePath);
|
||||
}
|
||||
|
||||
public void uploadRoutes(int accessRules, @NonNull BookmarkCategory bookmarkCategory)
|
||||
{
|
||||
nativeUploadToCatalog(accessRules, bookmarkCategory.getId());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getCatalogDeeplink(long catId)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
package com.mapswithme.maps.dialog;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ProgressDialogFragment extends DialogFragment
|
||||
{
|
||||
private static final String EXTRA_TITLE = "title";
|
||||
private static final String EXTRA_CANCELABLE = "cancelable";
|
||||
private static final String EXTRA_RETAIN_INSTANCE = "retain_instance";
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private TextView mMessageView;
|
||||
|
||||
public ProgressDialogFragment()
|
||||
{
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static ProgressDialogFragment newInstance(@NonNull String title)
|
||||
{
|
||||
return newInstance(title, false, true);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static ProgressDialogFragment newInstance(@NonNull String title, boolean cancelable,
|
||||
boolean retainInstance)
|
||||
{
|
||||
ProgressDialogFragment fr = new ProgressDialogFragment();
|
||||
fr.setArguments(getArgs(title, cancelable, retainInstance));
|
||||
return fr;
|
||||
}
|
||||
|
||||
public static Bundle getArgs(@NonNull String title, boolean cancelable, boolean retainInstance)
|
||||
{
|
||||
Bundle args = new Bundle();
|
||||
args.putString(EXTRA_TITLE, title);
|
||||
args.putBoolean(EXTRA_CANCELABLE, cancelable);
|
||||
args.putBoolean(EXTRA_RETAIN_INSTANCE, retainInstance);
|
||||
return args;
|
||||
}
|
||||
|
||||
protected void setCancelResult()
|
||||
{
|
||||
Fragment targetFragment = getTargetFragment();
|
||||
if (targetFragment != null)
|
||||
targetFragment.onActivityResult(getTargetRequestCode(), Activity.RESULT_CANCELED, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Bundle args = Objects.requireNonNull(getArguments());
|
||||
boolean retainInstance = args.getBoolean(EXTRA_RETAIN_INSTANCE, true);
|
||||
setRetainInstance(retainInstance);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public final Dialog onCreateDialog(Bundle savedInstanceState)
|
||||
{
|
||||
return onCreateProgressDialog();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
protected AlertDialog onCreateProgressDialog()
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
LayoutInflater inflater = LayoutInflater.from(getActivity());
|
||||
View view = inflater.inflate(R.layout.indeterminated_progress_dialog, null, false);
|
||||
Bundle args = Objects.requireNonNull(getArguments());
|
||||
String title = args.getString(EXTRA_TITLE);
|
||||
mMessageView.setText(title);
|
||||
mMessageView = view.findViewById(R.id.message);
|
||||
builder.setView(view);
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.setCanceledOnTouchOutside(args.getBoolean(EXTRA_CANCELABLE, false));
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog)
|
||||
{
|
||||
setCancelResult();
|
||||
}
|
||||
|
||||
public boolean isShowing()
|
||||
{
|
||||
Dialog dialog = getDialog();
|
||||
return dialog != null && dialog.isShowing();
|
||||
}
|
||||
|
||||
public void setMessage(@NonNull CharSequence message)
|
||||
{
|
||||
mMessageView.setText(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView()
|
||||
{
|
||||
if (getDialog() != null && getRetainInstance())
|
||||
getDialog().setDismissMessage(null);
|
||||
super.onDestroyView();
|
||||
}
|
||||
}
|
|
@ -1,14 +1,34 @@
|
|||
package com.mapswithme.maps.ugc.routes;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
|
||||
|
||||
public class UgcRouteSharingOptionsActivity extends BaseMwmFragmentActivity
|
||||
{
|
||||
|
||||
private static final String SHARING_OPTIONS_FRAGMENT_TAG = "sharing_options_fragment";
|
||||
|
||||
@Override
|
||||
protected void safeOnCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.safeOnCreate(savedInstanceState);
|
||||
setContentView(R.layout.ugc_route_sharing_options_activity);
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
Fragment fragment = fm.findFragmentByTag(SHARING_OPTIONS_FRAGMENT_TAG);
|
||||
if (fragment == null)
|
||||
fm.beginTransaction()
|
||||
.add(R.id.fragment_container, new UgcSharingOptionsFragment(), SHARING_OPTIONS_FRAGMENT_TAG)
|
||||
.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Fragment> getFragmentClass()
|
||||
{
|
||||
return UgcSharingOptionsFragment.class;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,9 @@ import android.content.Intent;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
|
@ -17,13 +19,22 @@ import android.widget.TextView;
|
|||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.auth.BaseMwmAuthorizationFragment;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.CatalogTagsGroup;
|
||||
import com.mapswithme.maps.dialog.AlertDialog;
|
||||
import com.mapswithme.maps.dialog.ProgressDialogFragment;
|
||||
import com.mapswithme.maps.widget.ToolbarController;
|
||||
import com.mapswithme.util.ConnectionState;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
public class UgcSharingOptionsFragment extends BaseMwmAuthorizationFragment
|
||||
public class UgcSharingOptionsFragment extends BaseMwmAuthorizationFragment implements BookmarkManager.BookmarksCatalogListener
|
||||
{
|
||||
private static final String NO_NETWORK_CONNECTION_DIALOG_TAG = "no_network_connection_dialog";
|
||||
private static final String UPLOADING_PROGRESS_DIALOG_TAG = "uploading_progress_dialog";
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private View mGetDirectLinkContainer;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
|
@ -45,6 +56,7 @@ public class UgcSharingOptionsFragment extends BaseMwmAuthorizationFragment
|
|||
@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
View root = inflater.inflate(R.layout.fragment_ugc_routes_sharing_options, container, false);
|
||||
mGetDirectLinkContainer = root.findViewById(R.id.get_direct_link_container);
|
||||
initClickListeners(root);
|
||||
TextView licenceAgreementText = root.findViewById(R.id.license_agreement_message);
|
||||
|
||||
|
@ -111,7 +123,59 @@ public class UgcSharingOptionsFragment extends BaseMwmAuthorizationFragment
|
|||
|
||||
private void onGetDirectLinkClicked()
|
||||
{
|
||||
onUploadBtnClicked();
|
||||
}
|
||||
|
||||
private void onUploadBtnClicked()
|
||||
{
|
||||
if (isNetworkConnectionAbsent())
|
||||
{
|
||||
showNoNetworkConnectionDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
if (isAuthorized())
|
||||
onPostAuthCompleted();
|
||||
else
|
||||
authorize();
|
||||
}
|
||||
|
||||
private void onPostAuthCompleted()
|
||||
{
|
||||
if (isDirectLinkUploadMode())
|
||||
requestDirectLink();
|
||||
else
|
||||
openTagsScreen();
|
||||
}
|
||||
|
||||
private boolean isDirectLinkUploadMode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private void requestDirectLink()
|
||||
{
|
||||
showProgress();
|
||||
BookmarkManager.INSTANCE.uploadRoutes(1, null);
|
||||
}
|
||||
|
||||
private void showProgress()
|
||||
{
|
||||
String title = getString(R.string.upload_and_publish_progress_text);
|
||||
ProgressDialogFragment dialog = ProgressDialogFragment.newInstance(title);
|
||||
getFragmentManager()
|
||||
.beginTransaction()
|
||||
.add(dialog, UPLOADING_PROGRESS_DIALOG_TAG)
|
||||
.commitAllowingStateLoss();
|
||||
}
|
||||
|
||||
|
||||
private void hideProgress()
|
||||
{
|
||||
FragmentManager fm = getFragmentManager();
|
||||
DialogFragment frag = (DialogFragment) fm.findFragmentByTag(UPLOADING_PROGRESS_DIALOG_TAG);
|
||||
if (frag != null)
|
||||
frag.dismissAllowingStateLoss();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -124,13 +188,28 @@ public class UgcSharingOptionsFragment extends BaseMwmAuthorizationFragment
|
|||
|
||||
private void requestPublishing(@NonNull Intent data)
|
||||
{
|
||||
showProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
BookmarkManager.INSTANCE.addCatalogListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
super.onStop();
|
||||
BookmarkManager.INSTANCE.removeCatalogListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthorizationFinish(boolean success)
|
||||
{
|
||||
|
||||
if (success)
|
||||
onPostAuthCompleted();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -150,4 +229,52 @@ public class UgcSharingOptionsFragment extends BaseMwmAuthorizationFragment
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onImportStarted(@NonNull String serverId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onImportFinished(@NonNull String serverId, long catId, boolean successful)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTagsReceived(boolean successful, @NonNull CatalogTagsGroup[] tagsGroups)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUploadStarted(long originCategoryId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUploadFinished(int uploadResult, @NonNull String description,
|
||||
long originCategoryId, long resultCategoryId)
|
||||
{
|
||||
|
||||
if (isOkResult(uploadResult))
|
||||
{
|
||||
hideProgress();
|
||||
if (isDirectLinkUploadMode())
|
||||
{
|
||||
/* not implemented yet */
|
||||
}
|
||||
else
|
||||
{
|
||||
UiUtils.hide(mGetDirectLinkContainer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOkResult(int uploadResult)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue