theme changed
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
package ch.pizzaleu.android.helper;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import ch.pizzaleu.android.R;
|
||||
import ch.pizzaleu.android.activity.BaseActivity;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 04/10/2017.
|
||||
*/
|
||||
|
||||
public class DateTimeHelper {
|
||||
|
||||
public static long getMillisFromDateString(String dateString){
|
||||
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Calendar calendar = null;
|
||||
try {
|
||||
Date date = formatter.parse(dateString);
|
||||
calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
return calendar.getTimeInMillis();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFormattedDateFromDateString(String dateString){
|
||||
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Calendar calendar = null;
|
||||
try {
|
||||
Date date = formatter.parse(dateString);
|
||||
calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
return calendar.get(Calendar.DAY_OF_MONTH) + " " +
|
||||
getMonthName(calendar.get(Calendar.MONTH)) + " " +
|
||||
calendar.get(Calendar.YEAR);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static String getMonthName(int monthIndex){
|
||||
switch (monthIndex){
|
||||
case 0:
|
||||
return BaseActivity.currentActivity.getString(R.string.month_name_january);
|
||||
case 1:
|
||||
return BaseActivity.currentActivity.getString(R.string.month_name_february);
|
||||
case 2:
|
||||
return BaseActivity.currentActivity.getString(R.string.month_name_march);
|
||||
case 3:
|
||||
return BaseActivity.currentActivity.getString(R.string.month_name_april);
|
||||
case 4:
|
||||
return BaseActivity.currentActivity.getString(R.string.month_name_may);
|
||||
case 5:
|
||||
return BaseActivity.currentActivity.getString(R.string.month_name_jun);
|
||||
case 6:
|
||||
return BaseActivity.currentActivity.getString(R.string.month_name_july);
|
||||
case 7:
|
||||
return BaseActivity.currentActivity.getString(R.string.month_name_august);
|
||||
case 8:
|
||||
return BaseActivity.currentActivity.getString(R.string.month_name_september);
|
||||
case 9:
|
||||
return BaseActivity.currentActivity.getString(R.string.month_name_october);
|
||||
case 10:
|
||||
return BaseActivity.currentActivity.getString(R.string.month_name_november);
|
||||
case 11:
|
||||
return BaseActivity.currentActivity.getString(R.string.month_name_december);
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
338
app/src/main/java/ch/pizzaleu/android/helper/DialogHelper.java
Normal file
338
app/src/main/java/ch/pizzaleu/android/helper/DialogHelper.java
Normal file
@@ -0,0 +1,338 @@
|
||||
package ch.pizzaleu.android.helper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import ch.pizzaleu.android.R;
|
||||
import ch.pizzaleu.android.activity.BaseActivity;
|
||||
import ch.pizzaleu.android.activity.LoginActivity;
|
||||
import ch.pizzaleu.android.activity.RegisterActivity;
|
||||
|
||||
public class DialogHelper {
|
||||
|
||||
private static MaterialDialog loadingDialog;
|
||||
|
||||
public static void showDialogWithPositiveButton(Context context, String message) {
|
||||
showDialogWithPositiveButton("", context, message);
|
||||
}
|
||||
|
||||
public static void showDialogWithPositiveButton(String title, Context context, String message) {
|
||||
|
||||
if(title.isEmpty())
|
||||
title = context.getString(R.string.app_name);
|
||||
|
||||
new MaterialDialog.Builder(context)
|
||||
.title(title)
|
||||
.content(message)
|
||||
.titleColorRes(R.color.red)
|
||||
.contentColorRes(R.color.black)
|
||||
.positiveText(R.string.ok)
|
||||
.positiveColor(ContextCompat.getColor(context, R.color.colorPrimary))
|
||||
.onPositive(new MaterialDialog.SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
|
||||
//BaseActivity.currentActivity.onBackPressed();
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.typeface("Quicksand-Medium.ttf", "Quicksand-Regular.ttf")
|
||||
.show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void showAlertDialog(Context context, String content) {
|
||||
|
||||
if(context == null)
|
||||
return;
|
||||
|
||||
new MaterialDialog.Builder(context)
|
||||
.title(R.string.alert)
|
||||
.content(content)
|
||||
.titleColorRes(R.color.red)
|
||||
.contentColorRes(R.color.black)
|
||||
.positiveText(R.string.ok)
|
||||
.positiveColor(ContextCompat.getColor(context, R.color.colorPrimary))
|
||||
.typeface("Quicksand-Medium.ttf", "Quicksand-Regular.ttf")
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void showFailedDialog() {
|
||||
|
||||
new MaterialDialog.Builder(BaseActivity.currentActivity)
|
||||
.title(R.string.alert)
|
||||
.content(BaseActivity.currentActivity.getString(R.string.failed))
|
||||
.titleColorRes(R.color.red)
|
||||
.contentColorRes(R.color.black)
|
||||
.positiveText(R.string.ok)
|
||||
.positiveColor(ContextCompat.getColor(BaseActivity.currentActivity, R.color.colorPrimary))
|
||||
.typeface("Quicksand-Medium.ttf", "Quicksand-Regular.ttf")
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void showNoNetworkDialog() {
|
||||
|
||||
new MaterialDialog.Builder(BaseActivity.currentActivity)
|
||||
.title(R.string.alert)
|
||||
.content(BaseActivity.currentActivity.getString(R.string.no_network_message))
|
||||
.titleColorRes(R.color.red)
|
||||
.contentColorRes(R.color.black)
|
||||
.positiveText(R.string.ok)
|
||||
.positiveColor(ContextCompat.getColor(BaseActivity.currentActivity, R.color.colorPrimary))
|
||||
.onPositive(new MaterialDialog.SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
|
||||
BaseActivity.currentActivity.finishAffinity();
|
||||
}
|
||||
})
|
||||
.typeface("Quicksand-Medium.ttf", "Quicksand-Regular.ttf")
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void showLoadingDialog(){
|
||||
if(loadingDialog != null && loadingDialog.isShowing())
|
||||
return;
|
||||
loadingDialog = new MaterialDialog.Builder(BaseActivity.currentActivity)
|
||||
.content(BaseActivity.currentActivity.getString(R.string.loading))
|
||||
.titleColorRes(R.color.red)
|
||||
.contentColorRes(R.color.black)
|
||||
.cancelable(false)
|
||||
.progress(true, 0)
|
||||
.progressIndeterminateStyle(true)
|
||||
.typeface("Quicksand-Medium.ttf", "Quicksand-Regular.ttf")
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void hideLoadingDialog(){
|
||||
if(loadingDialog != null && loadingDialog.isShowing()){
|
||||
loadingDialog.dismiss();
|
||||
loadingDialog = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void showTwoButtonsDialog(Context context, String message,
|
||||
MaterialDialog.SingleButtonCallback positiveButtonCallback,
|
||||
MaterialDialog.SingleButtonCallback negativeButtonCallback){
|
||||
showTwoButtonsDialog(
|
||||
context,
|
||||
message,
|
||||
R.string.ok,
|
||||
positiveButtonCallback,
|
||||
R.string.cancel,
|
||||
negativeButtonCallback);
|
||||
}
|
||||
|
||||
public static void showTwoButtonsDialog(Context context,
|
||||
String message,
|
||||
int positiveTextResId,
|
||||
MaterialDialog.SingleButtonCallback positiveButtonCallback,
|
||||
int negativeTextResId,
|
||||
MaterialDialog.SingleButtonCallback negativeButtonCallback){
|
||||
new MaterialDialog.Builder(context)
|
||||
.title(R.string.alert)
|
||||
.content(message)
|
||||
.titleColorRes(R.color.red)
|
||||
.contentColorRes(R.color.black)
|
||||
.positiveText(positiveTextResId)
|
||||
.onPositive(positiveButtonCallback)
|
||||
.negativeText(negativeTextResId)
|
||||
.onNegative(negativeButtonCallback)
|
||||
.typeface("Quicksand-Medium.ttf", "Quicksand-Regular.ttf")
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void showTwoButtonsDialog(String title,
|
||||
String message,
|
||||
int positiveTextResId,
|
||||
MaterialDialog.SingleButtonCallback positiveButtonCallback,
|
||||
int negativeTextResId,
|
||||
MaterialDialog.SingleButtonCallback negativeButtonCallback){
|
||||
showTwoButtonsDialog(
|
||||
title,
|
||||
message,
|
||||
positiveTextResId,
|
||||
positiveButtonCallback,
|
||||
negativeTextResId,
|
||||
negativeButtonCallback,
|
||||
true);
|
||||
}
|
||||
|
||||
public static void showTwoButtonsDialog(String title,
|
||||
String message,
|
||||
int positiveTextResId,
|
||||
MaterialDialog.SingleButtonCallback positiveButtonCallback,
|
||||
int negativeTextResId,
|
||||
MaterialDialog.SingleButtonCallback negativeButtonCallback,
|
||||
boolean isCancelable){
|
||||
new MaterialDialog.Builder(BaseActivity.currentActivity)
|
||||
.title(title)
|
||||
.content(message)
|
||||
.titleColorRes(R.color.red)
|
||||
.contentColorRes(R.color.black)
|
||||
.positiveText(positiveTextResId)
|
||||
.onPositive(positiveButtonCallback)
|
||||
.negativeText(negativeTextResId)
|
||||
.onNegative(negativeButtonCallback)
|
||||
.cancelable(isCancelable)
|
||||
.typeface("Quicksand-Medium.ttf", "Quicksand-Regular.ttf")
|
||||
.show();
|
||||
}
|
||||
|
||||
|
||||
public static void showNeedToLoginDialog(int messageResourceId){
|
||||
|
||||
MaterialDialog dialog = new MaterialDialog.Builder(BaseActivity.currentActivity)
|
||||
.title(R.string.alert)
|
||||
.content(BaseActivity.currentActivity.getString(messageResourceId))
|
||||
.titleColorRes(R.color.red)
|
||||
.contentColorRes(R.color.black)
|
||||
.positiveText(R.string.button_login)
|
||||
.onPositive(new MaterialDialog.SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
|
||||
Intent loginIntent = new Intent(BaseActivity.currentActivity, LoginActivity.class);
|
||||
loginIntent.putExtra("showBackIcon", true);
|
||||
BaseActivity.currentActivity.startActivity(loginIntent);
|
||||
}
|
||||
})
|
||||
.negativeText(R.string.register_text)
|
||||
.onNegative(new MaterialDialog.SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
|
||||
BaseActivity.currentActivity.startActivity(new Intent(BaseActivity.currentActivity, RegisterActivity.class));
|
||||
}
|
||||
})
|
||||
.neutralText(R.string.cancel_all_caps)
|
||||
//.onNeutral()
|
||||
.typeface("Quicksand-Medium.ttf", "Quicksand-Regular.ttf")
|
||||
.build();
|
||||
|
||||
dialog.getActionButton(DialogAction.POSITIVE).setTextSize(12);
|
||||
dialog.getActionButton(DialogAction.NEGATIVE).setTextSize(12);
|
||||
dialog.getActionButton(DialogAction.NEUTRAL).setTextSize(12);
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
public static void showUpdateAppDialog(Context context) {
|
||||
|
||||
new MaterialDialog.Builder(context)
|
||||
.title(R.string.alert)
|
||||
.content(R.string.alert_update_app)
|
||||
.titleColorRes(R.color.red)
|
||||
.contentColorRes(R.color.black)
|
||||
.positiveText(R.string.update_app)
|
||||
.positiveColor(ContextCompat.getColor(context, R.color.colorPrimary))
|
||||
.cancelable(false)
|
||||
.onPositive(new MaterialDialog.SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse("market://details?id=ch.pizzaleu.android"));
|
||||
BaseActivity.currentActivity.startActivity(intent);
|
||||
BaseActivity.currentActivity.finishAffinity();
|
||||
}
|
||||
})
|
||||
.typeface("Quicksand-Medium.ttf", "Quicksand-Regular.ttf")
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void showOneButtonDialogWithCallback(String message,
|
||||
MaterialDialog.SingleButtonCallback singleButtonCallback){
|
||||
new MaterialDialog.Builder(BaseActivity.currentActivity)
|
||||
.title(R.string.app_name)
|
||||
.content(message)
|
||||
.titleColorRes(R.color.red)
|
||||
.contentColorRes(R.color.black)
|
||||
.positiveText(R.string.ok)
|
||||
.onPositive(singleButtonCallback)
|
||||
.typeface("Quicksand-Medium.ttf", "Quicksand-Regular.ttf")
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void showOneButtonDialogWithDismissListener(String message,
|
||||
DialogInterface.OnDismissListener dismissListener){
|
||||
new MaterialDialog.Builder(BaseActivity.currentActivity)
|
||||
.title(R.string.app_name)
|
||||
.content(message)
|
||||
.titleColorRes(R.color.red)
|
||||
.contentColorRes(R.color.black)
|
||||
.positiveText(R.string.ok)
|
||||
.dismissListener(dismissListener)
|
||||
.typeface("Quicksand-Medium.ttf", "Quicksand-Regular.ttf")
|
||||
.show();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public static void showPasswordResetDialog(final Context context) {
|
||||
|
||||
new MaterialDialog.Builder(context)
|
||||
.title(R.string.app_name)
|
||||
.content(R.string.password_reset)
|
||||
.titleColorRes(R.color.red)
|
||||
.contentColorRes(R.color.black)
|
||||
.positiveText(R.string.ok)
|
||||
.positiveColor(ContextCompat.getColor(context, R.color.colorPrimary))
|
||||
.cancelable(false)
|
||||
.onPositive(new MaterialDialog.SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
|
||||
Intent intent = new Intent(context, LoginActivity.class);
|
||||
BaseActivity.currentActivity.startActivity(intent);
|
||||
BaseActivity.currentActivity.finishAffinity();
|
||||
}
|
||||
})
|
||||
.typeface("Quicksand-Medium.ttf", "Quicksand-Regular.ttf")
|
||||
.show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void showProfileUpdatedDialog(MaterialDialog.SingleButtonCallback singleButtonCallback) {
|
||||
new MaterialDialog.Builder(BaseActivity.currentActivity)
|
||||
.title(R.string.app_name)
|
||||
.content(R.string.profile_updated)
|
||||
.titleColorRes(R.color.red)
|
||||
.contentColorRes(R.color.black)
|
||||
.positiveText(R.string.ok)
|
||||
.cancelable(false)
|
||||
.onPositive(singleButtonCallback)
|
||||
.typeface("Quicksand-Medium.ttf", "Quicksand-Regular.ttf")
|
||||
.show();
|
||||
}
|
||||
*/
|
||||
|
||||
public static void showListDialog(ArrayList<String> itemList, MaterialDialog.ListCallback listCallback){
|
||||
new MaterialDialog.Builder(BaseActivity.currentActivity)
|
||||
.title(R.string.choose)
|
||||
.titleColorRes(R.color.red)
|
||||
.contentColorRes(R.color.black)
|
||||
.items(itemList)
|
||||
.itemsCallback(listCallback)
|
||||
.typeface("Quicksand-Medium.ttf", "Quicksand-Regular.ttf")
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void showStoreListDialog(ArrayList<String> itemList,
|
||||
MaterialDialog.ListCallback listCallback){
|
||||
new MaterialDialog.Builder(BaseActivity.currentActivity)
|
||||
.title(R.string.choose_store)
|
||||
.titleColorRes(R.color.red)
|
||||
.contentColorRes(R.color.black)
|
||||
.items(itemList)
|
||||
.itemsCallback(listCallback)
|
||||
.typeface("Quicksand-Medium.ttf", "Quicksand-Regular.ttf")
|
||||
.show();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package ch.pizzaleu.android.helper;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.os.Build;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import ch.pizzaleu.android.R;
|
||||
import ch.pizzaleu.android.activity.BaseActivity;
|
||||
|
||||
public class DisplayHelper {
|
||||
|
||||
public static int getScreenWidthInPixel(){
|
||||
DisplayMetrics displayMetrics = BaseActivity.currentActivity.getResources().getDisplayMetrics();
|
||||
return displayMetrics.widthPixels;
|
||||
}
|
||||
|
||||
public static int getScreenHeightInPixel(){
|
||||
DisplayMetrics displayMetrics = BaseActivity.currentActivity.getResources().getDisplayMetrics();
|
||||
return displayMetrics.heightPixels;
|
||||
}
|
||||
|
||||
public static int dpToPx(int dp) {
|
||||
DisplayMetrics displayMetrics = BaseActivity.currentActivity.getResources().getDisplayMetrics();
|
||||
return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
|
||||
}
|
||||
|
||||
public static int pxToDp(int px) {
|
||||
DisplayMetrics displayMetrics = BaseActivity.currentActivity.getResources().getDisplayMetrics();
|
||||
return Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public static void changeStatusColor() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
|
||||
return;
|
||||
Window window = BaseActivity.currentActivity.getWindow();
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
window.setStatusBarColor(ContextCompat.getColor(BaseActivity.currentActivity, R.color.main_black));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package ch.pizzaleu.android.helper;
|
||||
|
||||
import android.widget.ImageView;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import ch.pizzaleu.android.activity.BaseActivity;
|
||||
|
||||
public class ImageLoadHelper {
|
||||
|
||||
public static void loadImage(ImageView imageView, String url){
|
||||
|
||||
if(url == null || url.isEmpty())
|
||||
url = "empty";
|
||||
|
||||
Picasso.with(BaseActivity.currentActivity)
|
||||
.load(url)
|
||||
//.placeholder(R.drawable.placeholder)
|
||||
//.placeholder(R.drawable.progress_animation)
|
||||
//.error(R.drawable.placeholder)
|
||||
//.resize(500, 0)
|
||||
//.onlyScaleDown()
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package ch.pizzaleu.android.helper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import ch.pizzaleu.android.activity.BaseActivity;
|
||||
|
||||
public class NetworkHelper {
|
||||
|
||||
public static boolean isNetworkAvailable(){
|
||||
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) BaseActivity.currentActivity.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
|
||||
|
||||
if (activeNetworkInfo == null)
|
||||
return false;
|
||||
|
||||
else if (!activeNetworkInfo.isConnected())
|
||||
return false;
|
||||
|
||||
else if (!activeNetworkInfo.isAvailable())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package ch.pizzaleu.android.helper;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PasswordHelper {
|
||||
|
||||
public static final Pattern EMAIL_ADDRESS_PATTERN = Pattern.compile(
|
||||
"[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
|
||||
"\\@" +
|
||||
"[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +
|
||||
"(" +
|
||||
"\\." +
|
||||
"[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +
|
||||
")+"
|
||||
);
|
||||
|
||||
public static final Pattern PASSWORD_PATTERN = Pattern.compile("^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{8,}$");
|
||||
}
|
||||
141
app/src/main/java/ch/pizzaleu/android/helper/PriceHelper.java
Normal file
141
app/src/main/java/ch/pizzaleu/android/helper/PriceHelper.java
Normal file
@@ -0,0 +1,141 @@
|
||||
package ch.pizzaleu.android.helper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import ch.pizzaleu.android.R;
|
||||
import ch.pizzaleu.android.activity.BaseActivity;
|
||||
import ch.pizzaleu.android.model.menu.MenuProductModel;
|
||||
import ch.pizzaleu.android.model.menu.MenuProductOptionValueModel;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 12/10/2017.
|
||||
*/
|
||||
|
||||
public class PriceHelper {
|
||||
|
||||
public static String getPriceWithCurreny(String price){
|
||||
price = roundFractions(price);
|
||||
return BaseActivity.currentActivity.getString(R.string.chf) + " " + price;
|
||||
}
|
||||
|
||||
public static String getPriceWithCurreny(Double price){
|
||||
String priceString = roundFractions(String.valueOf(price));
|
||||
return BaseActivity.currentActivity.getString(R.string.chf) + " " + priceString;
|
||||
}
|
||||
|
||||
public static String getPriceWithCurrenyAndFractions(Double price){
|
||||
return BaseActivity.currentActivity.getString(R.string.chf) + " " + price;
|
||||
}
|
||||
|
||||
public static String removeCurrencyFromPrice(String priceWithCurreny){
|
||||
/*
|
||||
try {
|
||||
String currencyText = BaseActivity.currentActivity.getString(R.string.chf);
|
||||
String priceWithoutCurrency = priceWithCurreny.replace(currencyText, "");
|
||||
priceWithoutCurrency = priceWithoutCurrency.trim();
|
||||
return priceWithoutCurrency;
|
||||
}catch (Exception e){
|
||||
return priceWithCurreny.trim();
|
||||
}
|
||||
*/
|
||||
|
||||
String currencyText = BaseActivity.currentActivity.getString(R.string.chf);
|
||||
String priceWithoutCurrency = priceWithCurreny.replace(currencyText, "");
|
||||
priceWithoutCurrency = priceWithoutCurrency.trim();
|
||||
return priceWithoutCurrency;
|
||||
}
|
||||
|
||||
public static String calculatePriceAfterCountChanged(String oldPriceString, int oldCount, int newCount){
|
||||
Double oldPrice = stringToDouble(removeCurrencyFromPrice(oldPriceString));
|
||||
Double productOldPrice = oldPrice / oldCount;
|
||||
Double productNewPrice = productOldPrice * newCount;
|
||||
return getPriceWithCurreny(productNewPrice);
|
||||
}
|
||||
|
||||
public static String calculatePriceAfterRadioOptionValueChanged(int count,
|
||||
MenuProductModel menuProductModel,
|
||||
MenuProductOptionValueModel menuProductOptionValueModel){
|
||||
|
||||
Double productPrice = stringToDouble(menuProductModel.getPrice());
|
||||
|
||||
switch (menuProductOptionValueModel.getPrice_prefix()){
|
||||
case "+":
|
||||
productPrice += stringToDouble(menuProductOptionValueModel.getPrice());
|
||||
break;
|
||||
case "-":
|
||||
productPrice -= stringToDouble(menuProductOptionValueModel.getPrice());
|
||||
break;
|
||||
}
|
||||
|
||||
return getPriceWithCurreny(productPrice * count);
|
||||
|
||||
}
|
||||
|
||||
public static String calculatePriceAfterCheckboxOptionValueChanged(int count,
|
||||
MenuProductModel menuProductModel,
|
||||
ArrayList<MenuProductOptionValueModel> menuProductOptionValueModelList){
|
||||
|
||||
Double productPrice = stringToDouble(menuProductModel.getPrice());
|
||||
|
||||
for(MenuProductOptionValueModel menuProductOptionValueModel : menuProductOptionValueModelList){
|
||||
if(menuProductOptionValueModel.isSelected()){
|
||||
switch (menuProductOptionValueModel.getPrice_prefix()){
|
||||
case "+":
|
||||
productPrice += stringToDouble(menuProductOptionValueModel.getPrice());
|
||||
break;
|
||||
case "-":
|
||||
productPrice -= stringToDouble(menuProductOptionValueModel.getPrice());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return getPriceWithCurreny(productPrice * count);
|
||||
|
||||
}
|
||||
|
||||
public static String getProductOptionPriceText(MenuProductOptionValueModel productOptionValueModel){
|
||||
return new StringBuilder()
|
||||
.append(productOptionValueModel.getPrice_prefix())
|
||||
.append(" ")
|
||||
.append(BaseActivity.currentActivity.getString(R.string.chf))
|
||||
.append(" ")
|
||||
.append(roundFractions(productOptionValueModel.getPrice()))
|
||||
.toString();
|
||||
}
|
||||
|
||||
public static Double stringToDouble(String string){
|
||||
string = addFractions(string);
|
||||
Double dbl = Double.valueOf(string);
|
||||
return Math.floor(dbl * 100) / 100;
|
||||
}
|
||||
|
||||
public static String roundFractions(String price){
|
||||
|
||||
if(price.equals("0")){
|
||||
price = "0.-";
|
||||
}
|
||||
if(price.endsWith(".0")){
|
||||
price = price.replace(".0", ".-");
|
||||
}
|
||||
else if(price.endsWith(".00")){
|
||||
price = price.replace(".00", ".-");
|
||||
}
|
||||
else if(price.endsWith(".000")){
|
||||
price = price.replace(".000", ".-");
|
||||
}
|
||||
else if(price.endsWith(".0000")){
|
||||
price = price.replace(".0000", ".-");
|
||||
}
|
||||
return price;
|
||||
}
|
||||
|
||||
private static String addFractions(String price){
|
||||
if(price.endsWith(".-")){
|
||||
price = price.replace(".-", ".00");
|
||||
}
|
||||
return price;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
103
app/src/main/java/ch/pizzaleu/android/helper/SessionHelper.java
Normal file
103
app/src/main/java/ch/pizzaleu/android/helper/SessionHelper.java
Normal file
@@ -0,0 +1,103 @@
|
||||
package ch.pizzaleu.android.helper;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import ch.pizzaleu.android.model.CheckCouponModel;
|
||||
import ch.pizzaleu.android.model.CustomerTokenModel;
|
||||
import ch.pizzaleu.android.model.StoreModel;
|
||||
import ch.pizzaleu.android.model.UserModel;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 11/09/2017.
|
||||
*/
|
||||
|
||||
public class SessionHelper {
|
||||
|
||||
public static void saveCustomer(UserModel user){
|
||||
SharedPrefsHelper.saveUser(user);
|
||||
}
|
||||
|
||||
public static UserModel getUser(){
|
||||
return SharedPrefsHelper.getUser();
|
||||
}
|
||||
|
||||
public static void clearCustomerInfo(){
|
||||
SharedPrefsHelper.clearCustomerInfo();
|
||||
}
|
||||
|
||||
public static void saveCustomerToken(CustomerTokenModel customerToken){
|
||||
SharedPrefsHelper.saveCustomerToken(customerToken);
|
||||
}
|
||||
|
||||
public static CustomerTokenModel getCustomerToken(){
|
||||
return SharedPrefsHelper.getCustomerToken();
|
||||
}
|
||||
|
||||
public static void clearCustomerToken(){
|
||||
SharedPrefsHelper.clearCustomerToken();
|
||||
}
|
||||
|
||||
public static void setCustomerLoggedIn(boolean loggedId){
|
||||
SharedPrefsHelper.setCustomerLoggedIn(loggedId);
|
||||
}
|
||||
|
||||
public static boolean isCustomerLoggedIn(){
|
||||
return SharedPrefsHelper.isCustomerLoggedIn() &&
|
||||
SharedPrefsHelper.getCustomerToken().getStoreOfToken().getStoreName().toLowerCase().equals(
|
||||
SharedPrefsHelper.getSelectedStore().getStoreName().toLowerCase());
|
||||
}
|
||||
|
||||
public static void setSelectedStore(StoreModel storeModel){
|
||||
SharedPrefsHelper.saveSelectedStore(storeModel);
|
||||
}
|
||||
|
||||
public static StoreModel getSelectedStore(){
|
||||
StoreModel selectedStore = SharedPrefsHelper.getSelectedStore();
|
||||
return selectedStore;
|
||||
//return SharedPrefsHelper.getSelectedStore();
|
||||
}
|
||||
|
||||
public static void setIsFirstTime(boolean isFirstTime){
|
||||
SharedPrefsHelper.setIsFirstTime(isFirstTime);
|
||||
}
|
||||
|
||||
public static boolean isFirstTime(){
|
||||
return SharedPrefsHelper.isFirstTime();
|
||||
}
|
||||
|
||||
public static void logOut(){
|
||||
setCustomerLoggedIn(false);
|
||||
clearCustomerToken();
|
||||
clearCustomerInfo();
|
||||
}
|
||||
|
||||
public static void saveSelectedCoupon(CheckCouponModel couponModel){
|
||||
SharedPrefsHelper.saveSelectedCoupon(couponModel);
|
||||
}
|
||||
|
||||
public static CheckCouponModel getSelectedCoupon(){
|
||||
return SharedPrefsHelper.getSelectedCoupon();
|
||||
}
|
||||
|
||||
public static void clearSelectedCoupon(){
|
||||
SharedPrefsHelper.clearSelectedCoupon();
|
||||
}
|
||||
|
||||
public static Calendar getTokenDeathDate(String tokenDeathTime){
|
||||
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Calendar calendar = null;
|
||||
try {
|
||||
Date date = formatter.parse(tokenDeathTime);
|
||||
calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
return calendar;
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
return calendar;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
package ch.pizzaleu.android.helper;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
import ch.pizzaleu.android.activity.BaseActivity;
|
||||
import ch.pizzaleu.android.model.CategoryModel;
|
||||
import ch.pizzaleu.android.model.CheckCouponModel;
|
||||
import ch.pizzaleu.android.model.CustomerTokenModel;
|
||||
import ch.pizzaleu.android.model.StoreModel;
|
||||
import ch.pizzaleu.android.model.UserModel;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 25/06/2017.
|
||||
*/
|
||||
|
||||
public class SharedPrefsHelper {
|
||||
|
||||
private static final String SHARED_PREFS_NAME = "ch.pizzalink.android.preferences.";
|
||||
|
||||
private static final String PREF_KEY_CATEGORY_LIST = SHARED_PREFS_NAME + "categoryList";
|
||||
private static final String PREF_KEY_IGNORED_CATEGORY_ID_LIST = SHARED_PREFS_NAME + "ignoredCategoryIdList";
|
||||
private static final String PREF_KEY_PIZZA_CATEGORY_ID_LIST = SHARED_PREFS_NAME + "pizzaCategoryIdList";
|
||||
private static final String PREF_KEY_USER = SHARED_PREFS_NAME + "user";
|
||||
private static final String PREF_KEY_CUSTOMER_TOKEN = SHARED_PREFS_NAME + "customerToken";
|
||||
private static final String PREF_KEY_USER_LOG_IN_STATUS = SHARED_PREFS_NAME + "userLoginStatus";
|
||||
private static final String PREF_KEY_CART_ITEM_COUNT = SHARED_PREFS_NAME + "cartItemCount";
|
||||
private static final String PREF_KEY_CART_TOTAL_PRICE = SHARED_PREFS_NAME + "cartTotalPrice";
|
||||
private static final String PREF_KEY_USER_SELECTED_STORE = SHARED_PREFS_NAME + "selectedStore";
|
||||
private static final String PREF_KEY_IS_FIRST_TIME = SHARED_PREFS_NAME + "isFirstTime";
|
||||
private static final String PREF_KEY_SELECTED_COUPON = SHARED_PREFS_NAME + "selectedCoupon";
|
||||
|
||||
private static SharedPreferences sharedPreferences =
|
||||
BaseActivity.currentActivity
|
||||
.getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE);
|
||||
|
||||
private static SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
private static Gson gson = new Gson();
|
||||
|
||||
public static void saveCategoryList(ArrayList<CategoryModel> categoryList){
|
||||
String categoriesJsonString = gson.toJson(categoryList, new TypeToken<ArrayList<CategoryModel>>() {}.getType());
|
||||
editor.putString(PREF_KEY_CATEGORY_LIST, categoriesJsonString);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static ArrayList<CategoryModel> readCategoryList(){
|
||||
Type categoryListType = new TypeToken<ArrayList<CategoryModel>>(){}.getType();
|
||||
return gson.fromJson(sharedPreferences.getString(PREF_KEY_CATEGORY_LIST, ""), categoryListType);
|
||||
}
|
||||
|
||||
public static void saveIgnoredCategoryIdList(ArrayList<Integer> ignoredCategoryIdList){
|
||||
String ignoredCategoryIdsJsonString = gson.toJson(ignoredCategoryIdList, new TypeToken<ArrayList<Integer>>() {}.getType());
|
||||
editor.putString(PREF_KEY_IGNORED_CATEGORY_ID_LIST, ignoredCategoryIdsJsonString);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static ArrayList<Integer> readIgnoredCategoryIdList(){
|
||||
Type ignoredCategoryIdListType = new TypeToken<ArrayList<Integer>>(){}.getType();
|
||||
return gson.fromJson(sharedPreferences.getString(PREF_KEY_IGNORED_CATEGORY_ID_LIST, ""), ignoredCategoryIdListType);
|
||||
}
|
||||
|
||||
public static void savePizzaCategoryIdList(ArrayList<Integer> pizzaCategoryIdList){
|
||||
String ignoredCategoryIdsJsonString = gson.toJson(pizzaCategoryIdList, new TypeToken<ArrayList<Integer>>() {}.getType());
|
||||
editor.putString(PREF_KEY_PIZZA_CATEGORY_ID_LIST, ignoredCategoryIdsJsonString);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static ArrayList<Integer> readPizzaCategoryIdList(){
|
||||
Type pizzaCategoryIdList = new TypeToken<ArrayList<Integer>>(){}.getType();
|
||||
return gson.fromJson(sharedPreferences.getString(PREF_KEY_PIZZA_CATEGORY_ID_LIST, ""), pizzaCategoryIdList);
|
||||
}
|
||||
|
||||
public static void saveUser(UserModel user){
|
||||
editor.putString(PREF_KEY_USER, gson.toJson(user));
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static UserModel getUser(){
|
||||
return gson.fromJson(sharedPreferences.getString(PREF_KEY_USER, ""), UserModel.class);
|
||||
}
|
||||
|
||||
public static void clearCustomerInfo(){
|
||||
editor.remove(PREF_KEY_USER);
|
||||
editor.remove(PREF_KEY_CUSTOMER_TOKEN);
|
||||
editor.remove(PREF_KEY_CART_ITEM_COUNT);
|
||||
editor.remove(PREF_KEY_CART_TOTAL_PRICE);
|
||||
editor.remove(PREF_KEY_SELECTED_COUPON);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static void saveCustomerToken(CustomerTokenModel customerToken){
|
||||
editor.putString(PREF_KEY_CUSTOMER_TOKEN, gson.toJson(customerToken));
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static CustomerTokenModel getCustomerToken(){
|
||||
return gson.fromJson(sharedPreferences.getString(PREF_KEY_CUSTOMER_TOKEN, ""), CustomerTokenModel.class);
|
||||
}
|
||||
|
||||
public static void clearCustomerToken(){
|
||||
editor.remove(PREF_KEY_CUSTOMER_TOKEN);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static void setCustomerLoggedIn(boolean loggedId){
|
||||
editor.putBoolean(PREF_KEY_USER_LOG_IN_STATUS, loggedId);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static boolean isCustomerLoggedIn(){
|
||||
return sharedPreferences.getBoolean(PREF_KEY_USER_LOG_IN_STATUS, false);
|
||||
}
|
||||
|
||||
public static void setCartItemCount(int cartItemCount){
|
||||
editor.putInt(PREF_KEY_CART_ITEM_COUNT, cartItemCount);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static int getCartItemCount(){
|
||||
return sharedPreferences.getInt(PREF_KEY_CART_ITEM_COUNT, 0);
|
||||
}
|
||||
|
||||
public static String getCartTotalPrice(){
|
||||
return sharedPreferences.getString(PREF_KEY_CART_TOTAL_PRICE, "0");
|
||||
}
|
||||
|
||||
public static void setCartTotalPrice(String cartTotalPrice){
|
||||
editor.putString(PREF_KEY_CART_TOTAL_PRICE, cartTotalPrice);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static void saveSelectedStore(StoreModel storeModel){
|
||||
editor.putString(PREF_KEY_USER_SELECTED_STORE, gson.toJson(storeModel));
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static StoreModel getSelectedStore(){
|
||||
StoreModel selectedStoreModel = gson.fromJson(sharedPreferences.getString(PREF_KEY_USER_SELECTED_STORE, ""), StoreModel.class);
|
||||
if(selectedStoreModel == null){
|
||||
selectedStoreModel = new StoreModel();
|
||||
}
|
||||
return selectedStoreModel;
|
||||
}
|
||||
|
||||
public static void clearSelectedStore(){
|
||||
editor.remove(PREF_KEY_USER_SELECTED_STORE);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
|
||||
public static void setIsFirstTime(boolean isFirstTime){
|
||||
editor.putBoolean(PREF_KEY_IS_FIRST_TIME, isFirstTime);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static boolean isFirstTime(){
|
||||
return sharedPreferences.getBoolean(PREF_KEY_IS_FIRST_TIME, true);
|
||||
}
|
||||
|
||||
public static void saveSelectedCoupon(CheckCouponModel couponModel){
|
||||
editor.putString(PREF_KEY_SELECTED_COUPON, gson.toJson(couponModel));
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static CheckCouponModel getSelectedCoupon(){
|
||||
CheckCouponModel selectedCouponModel = gson.fromJson(sharedPreferences.getString(PREF_KEY_SELECTED_COUPON, ""), CheckCouponModel.class);
|
||||
if(selectedCouponModel != null &&
|
||||
selectedCouponModel.getStoreName().toLowerCase().equals(SessionHelper.getSelectedStore().getStoreName().toLowerCase())){
|
||||
return selectedCouponModel;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearSelectedCoupon(){
|
||||
editor.remove(PREF_KEY_SELECTED_COUPON);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
public static void saveCategoryList(ArrayList<Category> cats){
|
||||
|
||||
ArrayList<Category> categories = new ArrayList<>();
|
||||
|
||||
for(Category category : cats){
|
||||
|
||||
if(category.getName().toLowerCase().contains("&"))
|
||||
category.setName(category.getName().replaceAll("(?i)&", "&"));
|
||||
|
||||
if(!(category.getId().equals("1370") || category.getName().toLowerCase().equals("Uncategorized")))
|
||||
categories.add(category);
|
||||
}
|
||||
|
||||
sortCategories(categories);
|
||||
|
||||
String categoriesJsonString = gson.toJson(categories, new TypeToken<ArrayList<Category>>() {}.getType());
|
||||
editor.putString(PREF_KEY_CATEGORY_LIST, categoriesJsonString);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static List<Category> readCategoryList(){
|
||||
Type categoryListType = new TypeToken<ArrayList<Category>>(){}.getType();
|
||||
return gson.fromJson(sharedPreferences.getString(PREF_KEY_CATEGORY_LIST, ""), categoryListType);
|
||||
}
|
||||
|
||||
public static void saveAuthorList(ArrayList<Author> authors){
|
||||
String authorsJsonString = gson.toJson(authors, new TypeToken<ArrayList<Author>>() {}.getType());
|
||||
editor.putString(PREF_KEY_AUTHOR_LIST, authorsJsonString);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static List<Author> readAuthorList(){
|
||||
Type authorListType = new TypeToken<ArrayList<Author>>(){}.getType();
|
||||
return gson.fromJson(sharedPreferences.getString(PREF_KEY_AUTHOR_LIST, ""), authorListType);
|
||||
}
|
||||
|
||||
public static void saveMagazineList(ArrayList<Magazine> magazines){
|
||||
String magazinesJsonString = gson.toJson(magazines, new TypeToken<ArrayList<Magazine>>() {}.getType());
|
||||
editor.putString(PREF_KEY_MAGAZINE_LIST, magazinesJsonString);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static List<Magazine> readMagazineList(){
|
||||
Type magazineListType = new TypeToken<ArrayList<Magazine>>(){}.getType();
|
||||
return gson.fromJson(sharedPreferences.getString(PREF_KEY_MAGAZINE_LIST, ""), magazineListType);
|
||||
}
|
||||
|
||||
private static void sortCategories(ArrayList<Category> categories){
|
||||
|
||||
ArrayList<Category> sortedCategories = new ArrayList<>();
|
||||
|
||||
for(int i = 0; i < 5; i++){
|
||||
sortedCategories.add(categories.get(i));
|
||||
}
|
||||
|
||||
for(Category category : categories){
|
||||
|
||||
if(category.getName().toLowerCase(new Locale("tr", "TR")).equals("isviçre haberleri")) {
|
||||
sortedCategories.add(category);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(Category category : categories){
|
||||
|
||||
if(category.getName().toLowerCase(new Locale("tr", "TR")).equals("türkiyeden haberler")) {
|
||||
sortedCategories.add(category);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(Category category : categories){
|
||||
|
||||
if(!sortedCategories.contains(category))
|
||||
sortedCategories.add(category);
|
||||
}
|
||||
|
||||
categories.clear();
|
||||
categories.addAll(sortedCategories);
|
||||
sortedCategories.clear();
|
||||
}
|
||||
*/
|
||||
}
|
||||
41
app/src/main/java/ch/pizzaleu/android/helper/TextHelper.java
Normal file
41
app/src/main/java/ch/pizzaleu/android/helper/TextHelper.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package ch.pizzaleu.android.helper;
|
||||
|
||||
import android.text.Html;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class TextHelper {
|
||||
|
||||
public static String parseDate(String pureDate, boolean shouldShowTime){
|
||||
|
||||
if(pureDate == null || pureDate.trim().isEmpty())
|
||||
return "";
|
||||
// 2017-03-07 11:00:00.000000 9:0:0
|
||||
|
||||
String[] pureDateArray = pureDate.split(" ");
|
||||
String date = pureDateArray[0];
|
||||
|
||||
String[] dateArray = date.split("-");
|
||||
String year = dateArray[0];
|
||||
String month = dateArray[1];
|
||||
String day = dateArray[2];
|
||||
|
||||
if(!shouldShowTime)
|
||||
return day + "." + month + "." + year;
|
||||
|
||||
String time = pureDateArray[1];
|
||||
time = time.substring(0, 5);
|
||||
|
||||
return day + "." + month + "." + year + " " + "Saat " + time;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void setTextFromHTML(TextView textView, String html) {
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= 24)
|
||||
textView.setText(Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY));
|
||||
else
|
||||
textView.setText(Html.fromHtml(html));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
38
app/src/main/java/ch/pizzaleu/android/helper/ViewHelper.java
Normal file
38
app/src/main/java/ch/pizzaleu/android/helper/ViewHelper.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package ch.pizzaleu.android.helper;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import ch.pizzaleu.android.activity.BaseActivity;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 25/06/2017.
|
||||
*/
|
||||
|
||||
public class ViewHelper {
|
||||
|
||||
public static void toogleKeyboard() {
|
||||
InputMethodManager imm = (InputMethodManager) BaseActivity.currentActivity.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
if (imm.isActive()) {
|
||||
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); // hide
|
||||
} else {
|
||||
imm.toggleSoftInput(0, InputMethodManager.HIDE_IMPLICIT_ONLY); // show
|
||||
}
|
||||
}
|
||||
|
||||
public static void hideKeyboard() {
|
||||
View view = BaseActivity.currentActivity.getCurrentFocus();
|
||||
if (view != null) {
|
||||
InputMethodManager imm = (InputMethodManager) BaseActivity.currentActivity.
|
||||
getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void showKeyboard() {
|
||||
InputMethodManager imm = (InputMethodManager) BaseActivity.currentActivity.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
imm.toggleSoftInput(0, InputMethodManager.HIDE_IMPLICIT_ONLY); // show
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user