forked from organicmaps/organicmaps
Merge pull request #2541 from yunikkk/share-editor
[android] Share viral message.
This commit is contained in:
commit
d6daa8a23b
6 changed files with 65 additions and 19 deletions
|
@ -2,8 +2,8 @@
|
|||
<com.mapswithme.maps.widget.HeightLimitedFrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
11
android/res/menu/menu_viral_editor.xml
Normal file
11
android/res/menu/menu_viral_editor.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/share_message"
|
||||
android:title="@string/share_by_message"
|
||||
android:icon="@drawable/ic_share_message"/>
|
||||
|
||||
<item android:id="@+id/share"
|
||||
android:title="@string/share"
|
||||
android:icon="@drawable/ic_share"/>
|
||||
|
||||
</menu>
|
|
@ -43,13 +43,13 @@ import com.mapswithme.maps.downloader.MapManager;
|
|||
import com.mapswithme.maps.downloader.MigrationFragment;
|
||||
import com.mapswithme.maps.downloader.OnmapDownloader;
|
||||
import com.mapswithme.maps.editor.AuthFragment;
|
||||
import com.mapswithme.maps.editor.ViralFragment;
|
||||
import com.mapswithme.maps.editor.Editor;
|
||||
import com.mapswithme.maps.editor.EditorActivity;
|
||||
import com.mapswithme.maps.editor.EditorHostFragment;
|
||||
import com.mapswithme.maps.editor.FeatureCategoryActivity;
|
||||
import com.mapswithme.maps.editor.ReportActivity;
|
||||
import com.mapswithme.maps.editor.ReportFragment;
|
||||
import com.mapswithme.maps.editor.ViralFragment;
|
||||
import com.mapswithme.maps.location.LocationHelper;
|
||||
import com.mapswithme.maps.location.LocationPredictor;
|
||||
import com.mapswithme.maps.news.FirstStartFragment;
|
||||
|
|
|
@ -5,9 +5,9 @@ import android.app.Dialog;
|
|||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -16,7 +16,9 @@ import java.util.Random;
|
|||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmDialogFragment;
|
||||
import com.mapswithme.util.BottomSheetHelper;
|
||||
import com.mapswithme.util.ConnectionState;
|
||||
import com.mapswithme.util.sharing.ShareOption;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
public class ViralFragment extends BaseMwmDialogFragment
|
||||
|
@ -24,8 +26,7 @@ public class ViralFragment extends BaseMwmDialogFragment
|
|||
private static final String EXTRA_CONTRATS_SHOWN = "CongratsShown";
|
||||
private TextView mViral;
|
||||
|
||||
@StringRes
|
||||
private static int sViralText;
|
||||
private static String sViralText;
|
||||
|
||||
public static boolean shouldDisplay()
|
||||
{
|
||||
|
@ -48,16 +49,13 @@ public class ViralFragment extends BaseMwmDialogFragment
|
|||
mViral = (TextView) root.findViewById(R.id.viral);
|
||||
initViralText();
|
||||
mViral.setText(sViralText);
|
||||
// TODO set rank with correct text.
|
||||
root.findViewById(R.id.tell_friend).setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
dismiss();
|
||||
share();
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.EDITOR_SHARE_CLICK);
|
||||
// TODO send statistics
|
||||
// TODO open some share link
|
||||
}
|
||||
});
|
||||
root.findViewById(R.id.close).setOnClickListener(new View.OnClickListener()
|
||||
|
@ -72,6 +70,38 @@ public class ViralFragment extends BaseMwmDialogFragment
|
|||
return builder.setView(root).create();
|
||||
}
|
||||
|
||||
private void share()
|
||||
{
|
||||
// TODO add custom sharing in twitter and url to facebook sharing
|
||||
BottomSheetHelper.Builder sheet = BottomSheetHelper.create(getActivity())
|
||||
.sheet(R.menu.menu_viral_editor)
|
||||
.listener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item)
|
||||
{
|
||||
if (item.getItemId() == R.id.share_message)
|
||||
{
|
||||
ShareOption.SMS.share(getActivity(),
|
||||
getString(R.string.whatsnew_editor_message_1));
|
||||
}
|
||||
else
|
||||
{
|
||||
ShareOption.ANY.share(getActivity(),
|
||||
getString(R.string.whatsnew_editor_message_1),
|
||||
R.string.editor_sharing_title);
|
||||
}
|
||||
|
||||
dismiss();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (!ShareOption.SMS.isSupported(getActivity()))
|
||||
sheet.getMenu().removeItem(R.id.share_message);
|
||||
|
||||
sheet.tint().show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog)
|
||||
{
|
||||
|
@ -81,13 +111,20 @@ public class ViralFragment extends BaseMwmDialogFragment
|
|||
|
||||
private void initViralText()
|
||||
{
|
||||
if (sViralText != 0)
|
||||
if (sViralText != null)
|
||||
return;
|
||||
|
||||
if (new Random().nextBoolean())
|
||||
sViralText = R.string.editor_done_dialog_1;
|
||||
else
|
||||
sViralText = R.string.editor_done_dialog_2;
|
||||
switch (new Random().nextInt(2))
|
||||
{
|
||||
case 0:
|
||||
sViralText = getString(R.string.editor_done_dialog_1);
|
||||
break;
|
||||
case 1:
|
||||
sViralText = getString(R.string.editor_done_dialog_2, getUserEditorRank());
|
||||
break;
|
||||
default:
|
||||
sViralText = getString(R.string.editor_done_dialog_3);
|
||||
}
|
||||
}
|
||||
|
||||
// Counts fake editor rank based on number of total edits made by user.
|
||||
|
|
|
@ -45,7 +45,7 @@ public abstract class ShareOption
|
|||
super(R.string.share_by_message, new Intent(Intent.ACTION_VIEW));
|
||||
}
|
||||
|
||||
private void shareWithText(Activity activity, String body)
|
||||
public void share(Activity activity, String body)
|
||||
{
|
||||
Intent smsIntent = new Intent();
|
||||
TargetUtils.fillSmsIntent(activity, smsIntent, body);
|
||||
|
@ -61,7 +61,7 @@ public abstract class ShareOption
|
|||
final int bodyId = MapObject.isOfType(MapObject.MY_POSITION, mapObject) ? R.string.my_position_share_sms : R.string.bookmark_share_sms;
|
||||
final String body = activity.getString(bodyId, ge0Url, httpUrl);
|
||||
|
||||
shareWithText(activity, body);
|
||||
share(activity, body);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,11 +37,9 @@ public final class SharingHelper
|
|||
private static boolean sInitialized;
|
||||
private static final SharingHelper sInstance = new SharingHelper();
|
||||
|
||||
|
||||
private final SharedPreferences mPrefs = MwmApplication.get().getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE);
|
||||
private final Map<String, SharingTarget> mItems = new HashMap<>();
|
||||
|
||||
|
||||
private SharingHelper()
|
||||
{}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue