forked from organicmaps/organicmaps
Cleared promo activation trash.
This commit is contained in:
parent
39479def8e
commit
5afc425733
3 changed files with 1 additions and 253 deletions
|
@ -37,7 +37,6 @@ import com.mapswithme.maps.bookmarks.data.MapObject;
|
|||
import com.mapswithme.maps.bookmarks.data.MapObject.ApiPoint;
|
||||
import com.mapswithme.maps.bookmarks.data.ParcelablePoint;
|
||||
import com.mapswithme.maps.location.LocationService;
|
||||
import com.mapswithme.maps.promo.ActivationSettings;
|
||||
import com.mapswithme.maps.search.SearchController;
|
||||
import com.mapswithme.maps.settings.SettingsActivity;
|
||||
import com.mapswithme.maps.settings.StoragePathManager;
|
||||
|
@ -568,7 +567,7 @@ public class MWMActivity extends NvEventQueueActivity
|
|||
|
||||
public void onSearchClicked(View v)
|
||||
{
|
||||
if (!(mApplication.isProVersion() || ActivationSettings.isSearchActivated(this)))
|
||||
if (!mApplication.isProVersion())
|
||||
{
|
||||
showProVersionBanner(getString(R.string.search_available_in_pro_version));
|
||||
}
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package com.mapswithme.maps.promo;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
public class ActivationSettings
|
||||
{
|
||||
private final static String PREFIX = "MWM-AS:";
|
||||
private final static String PREFS_NAME = PREFIX + "name-";
|
||||
private final static String PARAM_SEARCH_ACTIVATED = PREFIX + "search";
|
||||
|
||||
public static boolean isSearchActivated(Context context)
|
||||
{
|
||||
SharedPreferences preferences = getPrefs(context);
|
||||
return preferences.getBoolean(PARAM_SEARCH_ACTIVATED, false);
|
||||
}
|
||||
|
||||
public static void setSearchActivated(Context context, boolean isActivated)
|
||||
{
|
||||
SharedPreferences preferences = getPrefs(context);
|
||||
preferences.edit().putBoolean(PARAM_SEARCH_ACTIVATED, isActivated).commit();
|
||||
}
|
||||
|
||||
private static SharedPreferences getPrefs(Context context)
|
||||
{
|
||||
return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
private ActivationSettings()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
|
@ -1,218 +0,0 @@
|
|||
package com.mapswithme.maps.promo;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.promo.request.PromoActivationRequest;
|
||||
import com.mapswithme.util.Utils;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class PromocodeActivationDialog extends Dialog
|
||||
implements OnClickListener, PromoActivationRequest.RequestListener
|
||||
{
|
||||
private EditText mPromoText;
|
||||
private TextView mErrorText;
|
||||
private Button mCancelBtn;
|
||||
private Button mActivateBtn;
|
||||
|
||||
private ProgressBar mProgressBar;
|
||||
private Handler mHandler;
|
||||
|
||||
// for www.computerbild.de
|
||||
private PromoActivationRequest mComputerBildRequest;
|
||||
|
||||
public PromocodeActivationDialog(Context context)
|
||||
{
|
||||
super(context);
|
||||
|
||||
mComputerBildRequest = new PromoActivationRequest()
|
||||
{
|
||||
@Override
|
||||
public boolean parseResponse(InputStream is)
|
||||
{
|
||||
@SuppressWarnings("resource")
|
||||
final Scanner scanner = new Scanner(is).useDelimiter("\\A");
|
||||
return scanner.hasNext() ? "VALID".equalsIgnoreCase(scanner.next()) : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL createUrl(String promoCode) throws MalformedURLException
|
||||
{
|
||||
final String strUrl = "https://mwm.cbapps.de/" + promoCode;
|
||||
return new URL(strUrl);
|
||||
}
|
||||
};
|
||||
|
||||
mComputerBildRequest.setRequestListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
|
||||
setContentView(R.layout.dlg_promo_activation);
|
||||
setUpView();
|
||||
setViewIsWaiting(false);
|
||||
hideError();
|
||||
|
||||
mHandler = new Handler();
|
||||
|
||||
// Track dialog creation
|
||||
Statistics.INSTANCE.trackPromocodeDialogOpenedEvent();
|
||||
}
|
||||
|
||||
private String getString(int id)
|
||||
{
|
||||
return getContext().getString(id);
|
||||
}
|
||||
|
||||
private void setUpView()
|
||||
{
|
||||
mPromoText = (EditText) findViewById(R.id.txt_promocode);
|
||||
mErrorText = (TextView) findViewById(R.id.txt_error);
|
||||
mCancelBtn = (Button) findViewById(R.id.btn_cancel);
|
||||
mActivateBtn = (Button) findViewById(R.id.btn_activate);
|
||||
mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
|
||||
|
||||
mCancelBtn.setOnClickListener(this);
|
||||
mActivateBtn.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
// Automatically show keyboard on start
|
||||
mPromoText.setOnFocusChangeListener(new View.OnFocusChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus)
|
||||
{
|
||||
if (hasFocus)
|
||||
{
|
||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setViewIsWaiting(boolean isWaiting)
|
||||
{
|
||||
mProgressBar.setVisibility(isWaiting ? View.VISIBLE : View.INVISIBLE);
|
||||
mActivateBtn.setEnabled(!isWaiting);
|
||||
mCancelBtn.setEnabled(!isWaiting);
|
||||
mPromoText.setEnabled(!isWaiting);
|
||||
setCancelable(!isWaiting);
|
||||
}
|
||||
|
||||
private void hideError()
|
||||
{
|
||||
mErrorText.setVisibility(View.GONE);
|
||||
mErrorText.setText(null);
|
||||
}
|
||||
|
||||
private void showError(CharSequence message)
|
||||
{
|
||||
mErrorText.setText(message);
|
||||
mErrorText.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
final int id = v.getId();
|
||||
if (id == R.id.btn_activate)
|
||||
activateCoupon();
|
||||
else if (id == R.id.btn_cancel)
|
||||
dismiss();
|
||||
}
|
||||
|
||||
private void activateCoupon()
|
||||
{
|
||||
setViewIsWaiting(true);
|
||||
hideError();
|
||||
|
||||
final String promoCode = mPromoText.getText().toString().trim();
|
||||
|
||||
new Thread()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
mComputerBildRequest.doRequst(promoCode);
|
||||
} catch (Exception e)
|
||||
{
|
||||
onError(e);
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure()
|
||||
{
|
||||
mHandler.post(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
setViewIsWaiting(false);
|
||||
showError(getString(R.string.promocode_failure));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess()
|
||||
{
|
||||
mHandler.post(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
setViewIsWaiting(false);
|
||||
ActivationSettings.setSearchActivated(getContext(), true);
|
||||
dismiss();
|
||||
Utils.toastShortcut(getContext(), getString(R.string.promocode_success));
|
||||
|
||||
// Track successful activation
|
||||
Statistics.INSTANCE.trackPromocodeActivatedEvent();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(final Exception ex)
|
||||
{
|
||||
mHandler.post(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
setViewIsWaiting(false);
|
||||
showError(getString(R.string.promocode_error));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue