splash functions
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion "25.0.2"
|
||||
compileSdkVersion 26
|
||||
buildToolsVersion "26.0.1"
|
||||
defaultConfig {
|
||||
applicationId "ch.pizzalink.android"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 25
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 26
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
@@ -24,10 +24,10 @@ dependencies {
|
||||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
|
||||
exclude group: 'com.android.support', module: 'support-annotations'
|
||||
})
|
||||
compile 'com.android.support:appcompat-v7:25.3.1'
|
||||
compile 'com.android.support:appcompat-v7:26.0.1'
|
||||
compile 'com.android.support.constraint:constraint-layout:1.0.2'
|
||||
compile 'com.android.support:recyclerview-v7:25.3.1'
|
||||
compile 'com.android.support:cardview-v7:25.3.1'
|
||||
compile 'com.android.support:recyclerview-v7:26.0.1'
|
||||
compile 'com.android.support:cardview-v7:26.0.1'
|
||||
compile 'com.google.android.gms:play-services-maps:11.0.4'
|
||||
compile 'com.google.android.gms:play-services-location:11.0.4'
|
||||
compile 'com.squareup.picasso:picasso:2.5.2'
|
||||
@@ -43,6 +43,7 @@ dependencies {
|
||||
compile 'io.nlopez.smartlocation:library:3.3.1'
|
||||
compile 'com.afollestad.material-dialogs:core:0.9.4.5'
|
||||
compile 'com.github.AndroidDeveloperLB:DialogShard:3'
|
||||
compile 'com.github.HITGIF:TextFieldBoxes:1.3.3'
|
||||
testCompile 'junit:junit:4.12'
|
||||
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="ch.pizzalink.android">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
|
||||
@@ -16,6 +16,12 @@ public class BaseActivity extends AppCompatActivity {
|
||||
|
||||
public static BaseActivity currentActivity;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setCurrentActivity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
@@ -2,9 +2,24 @@ package ch.pizzalink.android.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import ch.pizzalink.android.R;
|
||||
import ch.pizzalink.android.api.ApiErrorUtils;
|
||||
import ch.pizzalink.android.api.ApiService;
|
||||
import ch.pizzalink.android.helper.DialogHelper;
|
||||
import ch.pizzalink.android.helper.NetworkHelper;
|
||||
import ch.pizzalink.android.helper.SessionHelper;
|
||||
import ch.pizzalink.android.helper.SharedPrefsHelper;
|
||||
import ch.pizzalink.android.model.CategoryModel;
|
||||
import ch.pizzalink.android.model.responseModel.CategoryResponseModel;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class SplashActivity extends BaseActivity {
|
||||
|
||||
@@ -13,7 +28,83 @@ public class SplashActivity extends BaseActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_splash);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
startActivity(new Intent(this, MainActivity.class));
|
||||
if(NetworkHelper.isNetworkAvailable())
|
||||
getCategoryList();
|
||||
else
|
||||
DialogHelper.showNoNetworkDialog();
|
||||
//startActivity(new Intent(this, MainActivity.class));
|
||||
}
|
||||
|
||||
private void getCategoryList(){
|
||||
Call<CategoryResponseModel> call = ApiService.apiInterface.getAllCategories();
|
||||
call.enqueue(new Callback<CategoryResponseModel>() {
|
||||
@Override
|
||||
public void onResponse(Call<CategoryResponseModel> call, Response<CategoryResponseModel> response) {
|
||||
if(response.isSuccessful()){
|
||||
CategoryModel.checkNull(response.body().getData());
|
||||
SharedPrefsHelper.saveCategoryList(response.body().getData());
|
||||
checkCustomerToken();
|
||||
}
|
||||
else
|
||||
ApiErrorUtils.parseError(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<CategoryResponseModel> call, Throwable t) {
|
||||
DialogHelper.showFailedDialog();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void checkCustomerToken(){
|
||||
|
||||
if(SessionHelper.isCustomerLoggedIn()){
|
||||
if(SessionHelper.getCustomerToken().isCustomerTokenAlive())
|
||||
openActivity(MainActivity.class);
|
||||
else
|
||||
refreshCustomerToken();
|
||||
}
|
||||
else
|
||||
openActivity(WelcomeActivity.class);
|
||||
}
|
||||
|
||||
private void openActivity(final Class<?> cls){
|
||||
Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startActivity(new Intent(SplashActivity.this, cls));
|
||||
finish();
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
private void refreshCustomerToken(){
|
||||
/*
|
||||
Call<RefreshTokenResponseModel> call = ApiService.apiInterface.refreshCustomerToken(SessionManager.getCustomerToken().getRefreshToken());
|
||||
call.enqueue(new Callback<RefreshTokenResponseModel>() {
|
||||
@Override
|
||||
public void onResponse(Call<RefreshTokenResponseModel> call, Response<RefreshTokenResponseModel> response) {
|
||||
|
||||
ApiService.getInstance().reset();
|
||||
|
||||
if(response.isSuccessful() && response.body().isSuccess()) {
|
||||
SessionManager.saveCustomerToken(response.body().getCustomerToken(), Constants.PUSULA_CARD_MEMBER_TYPE_CUSTOMER);
|
||||
startMainActivity();
|
||||
}
|
||||
|
||||
else
|
||||
DialogHelper.showAlertDialog(BaseActivity.currentActivity, "Bir hata oluştu. Lütfen daha sonra tekrar deneyin.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<RefreshTokenResponseModel> call, Throwable t) {
|
||||
ApiService.getInstance().reset();
|
||||
DialogHelper.showAlertDialog(BaseActivity.currentActivity, "Bir hata oluştu. Lütfen daha sonra tekrar deneyin.");
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ package ch.pizzalink.android.api;
|
||||
public class ApiConstants {
|
||||
public static final int API_READ_TIMEOUT = 30;
|
||||
public static final int API_CONNECT_TIMEOUT = 10;
|
||||
public static final String API_PATH = "";
|
||||
public static final String API_PATH = "http://www.pizzalink.ch/";
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package ch.pizzalink.android.api;
|
||||
|
||||
public class ApiEndPoints {
|
||||
private static final String PREFIX = "services/admin/index.php?route=services/news/";
|
||||
public static final String API_GET_ALL_CATEGORIES = PREFIX + "getAllCategories";
|
||||
|
||||
private static final String PREFIX = "pizza2/index.php?route=mobile/service/";
|
||||
|
||||
public static final String API_GET_ALL_CATEGORIES = PREFIX + "getAllCategories&is_mobile=1";
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ch.pizzalink.android.api;
|
||||
|
||||
import ch.pizzalink.android.model.responseModel.CategoryResponseModel;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
@@ -13,6 +14,9 @@ import retrofit2.http.Query;
|
||||
|
||||
public interface ApiInterface {
|
||||
|
||||
@GET(ApiEndPoints.API_GET_ALL_CATEGORIES)
|
||||
Call<CategoryResponseModel> getAllCategories();
|
||||
|
||||
/*
|
||||
@GET(ApiEndPoints.API_GET_ALL_CATEGORIES)
|
||||
Call<CategoryListResponseModel> getAllCategories();
|
||||
|
||||
@@ -12,7 +12,7 @@ import ch.pizzalink.android.activity.BaseActivity;
|
||||
public class DialogHelper {
|
||||
|
||||
public static void showDialogWithPositiveButton(Context context, String content) {
|
||||
/*
|
||||
|
||||
new MaterialDialog.Builder(context)
|
||||
.title(R.string.alert)
|
||||
.content(content)
|
||||
@@ -21,14 +21,15 @@ public class DialogHelper {
|
||||
.onPositive(new MaterialDialog.SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
|
||||
BaseActivity.currentActivity.onBackPressed();
|
||||
//BaseActivity.currentActivity.onBackPressed();
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
public static void showAlertDialog(Context context, String content) {
|
||||
|
||||
if(context == null)
|
||||
@@ -42,6 +43,28 @@ public class DialogHelper {
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void showFailedDialog() {
|
||||
|
||||
new MaterialDialog.Builder(BaseActivity.currentActivity)
|
||||
.title(R.string.alert)
|
||||
.content(BaseActivity.currentActivity.getString(R.string.failed))
|
||||
.positiveText(R.string.ok)
|
||||
.positiveColor(ContextCompat.getColor(BaseActivity.currentActivity, R.color.colorPrimary))
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void showNoNetworkDialog() {
|
||||
|
||||
new MaterialDialog.Builder(BaseActivity.currentActivity)
|
||||
.title(R.string.alert)
|
||||
.content(BaseActivity.currentActivity.getString(R.string.no_network_message))
|
||||
.positiveText(R.string.ok)
|
||||
.positiveColor(ContextCompat.getColor(BaseActivity.currentActivity, R.color.colorPrimary))
|
||||
.show();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
public static void showDialogWithPositiveButtonCallback(Context context, String content,
|
||||
MaterialDialog.SingleButtonCallback positiveButtonCallback) {
|
||||
|
||||
|
||||
@@ -1,8 +1,69 @@
|
||||
package ch.pizzalink.android.helper;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import ch.pizzalink.android.model.CustomerTokenModel;
|
||||
import ch.pizzalink.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();
|
||||
}
|
||||
|
||||
public static void logOut(){
|
||||
setCustomerLoggedIn(false);
|
||||
clearCustomerToken();
|
||||
clearCustomerInfo();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ import java.util.Locale;
|
||||
|
||||
|
||||
import ch.pizzalink.android.activity.BaseActivity;
|
||||
import ch.pizzalink.android.model.CategoryModel;
|
||||
import ch.pizzalink.android.model.CustomerTokenModel;
|
||||
import ch.pizzalink.android.model.UserModel;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
@@ -21,60 +24,54 @@ import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
public class SharedPrefsHelper {
|
||||
|
||||
private final String SHARED_PREFS_NAME = "ch.pizzalink.android";
|
||||
private static final String SHARED_PREFS_NAME = "ch.pizzalink.android.preferences.";
|
||||
|
||||
private static final String PREF_NAME_NORMAL = "com.pusulamedia.android.preferences";
|
||||
private static final String PREF_KEY_CUSTOMER = "ch.pusulaswiss.android.preferences.customer";
|
||||
private static final String PREF_KEY_STORE_CUSTOMER = "ch.pusulaswiss.android.preferences.store_customer";
|
||||
private static final String PREF_KEY_CUSTOMER_TOKEN = "ch.pusulaswiss.android.preferences.customer_token";
|
||||
private static final String PREF_KEY_CUSTOMER_LOG_IN_STATUS = "ch.pusulaswiss.android.preferences.customer_log_in_status";
|
||||
private static final String PREF_KEY_CATEGORY_LIST = SHARED_PREFS_NAME + "categoryList";
|
||||
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_CATEGORY_LIST = "com.pusulamedia.android.category_list";
|
||||
private static final String PREF_KEY_AUTHOR_LIST = "com.pusulamedia.android.author_list";
|
||||
private static final String PREF_KEY_MAGAZINE_LIST = "com.pusulamedia.android.magazine_list";
|
||||
|
||||
private static SharedPreferences sharedPreferences = BaseActivity.currentActivity
|
||||
.getSharedPreferences(PREF_NAME_NORMAL, MODE_PRIVATE);
|
||||
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 saveCustomer(Customer customer){
|
||||
editor.putString(PREF_KEY_CUSTOMER, gson.toJson(customer));
|
||||
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 Customer getCustomer(){
|
||||
return gson.fromJson(sharedPreferences.getString(PREF_KEY_CUSTOMER, ""), Customer.class);
|
||||
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 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_CUSTOMER);
|
||||
editor.remove(PREF_KEY_USER);
|
||||
editor.remove(PREF_KEY_CUSTOMER_TOKEN);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static void saveStoreCustomer(StoreCustomer storeCustomer){
|
||||
editor.putString(PREF_KEY_STORE_CUSTOMER, gson.toJson(storeCustomer));
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static StoreCustomer getStoreCustomer(){
|
||||
return gson.fromJson(sharedPreferences.getString(PREF_KEY_STORE_CUSTOMER, ""), StoreCustomer.class);
|
||||
}
|
||||
|
||||
public static void clearStoreCustomerInfo(){
|
||||
editor.remove(PREF_KEY_STORE_CUSTOMER);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static void saveCustomerToken(CustomerToken customerToken){
|
||||
public static void saveCustomerToken(CustomerTokenModel customerToken){
|
||||
editor.putString(PREF_KEY_CUSTOMER_TOKEN, gson.toJson(customerToken));
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static CustomerToken getCustomerToken(){
|
||||
return gson.fromJson(sharedPreferences.getString(PREF_KEY_CUSTOMER_TOKEN, ""), CustomerToken.class);
|
||||
public static CustomerTokenModel getCustomerToken(){
|
||||
return gson.fromJson(sharedPreferences.getString(PREF_KEY_CUSTOMER_TOKEN, ""), CustomerTokenModel.class);
|
||||
}
|
||||
|
||||
public static void clearCustomerToken(){
|
||||
@@ -82,15 +79,17 @@ public class SharedPrefsHelper {
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
|
||||
public static void setCustomerLoggedIn(boolean loggedId){
|
||||
editor.putBoolean(PREF_KEY_CUSTOMER_LOG_IN_STATUS, loggedId);
|
||||
editor.putBoolean(PREF_KEY_USER_LOG_IN_STATUS, loggedId);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static boolean isCustomerLoggedIn(){
|
||||
return sharedPreferences.getBoolean(PREF_KEY_CUSTOMER_LOG_IN_STATUS, false);
|
||||
return sharedPreferences.getBoolean(PREF_KEY_USER_LOG_IN_STATUS, false);
|
||||
}
|
||||
|
||||
/*
|
||||
public static void saveCategoryList(ArrayList<Category> cats){
|
||||
|
||||
ArrayList<Category> categories = new ArrayList<>();
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package ch.pizzalink.android.model;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 26/09/2017.
|
||||
*/
|
||||
|
||||
public class CategoryModel {
|
||||
|
||||
@Expose
|
||||
@SerializedName("category_id")
|
||||
private int id;
|
||||
|
||||
@Expose
|
||||
@SerializedName("name")
|
||||
private String name;
|
||||
|
||||
@Expose
|
||||
@SerializedName("children")
|
||||
private ArrayList<CategoryModel> subCategoryList;
|
||||
|
||||
public void checkNull(){
|
||||
if(name == null)
|
||||
name = "";
|
||||
}
|
||||
|
||||
public static void checkNull(ArrayList<CategoryModel> categoryList){
|
||||
for (CategoryModel categoryModel : categoryList){
|
||||
categoryModel.checkNull();
|
||||
if(categoryModel.getSubCategoryList() != null &&
|
||||
categoryModel.getSubCategoryList().size() > 0){
|
||||
for(CategoryModel subCategoryModel : categoryModel.subCategoryList){
|
||||
subCategoryModel.checkNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ArrayList<CategoryModel> getSubCategoryList() {
|
||||
return subCategoryList;
|
||||
}
|
||||
|
||||
public void setSubCategoryList(ArrayList<CategoryModel> subCategoryList) {
|
||||
this.subCategoryList = subCategoryList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package ch.pizzalink.android.model;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 26/09/2017.
|
||||
*/
|
||||
|
||||
public class CustomerTokenModel {
|
||||
|
||||
@Expose
|
||||
@SerializedName("customer_token")
|
||||
private String token;
|
||||
|
||||
@Expose
|
||||
@SerializedName("token_death_time")
|
||||
private String expiresIn;
|
||||
|
||||
@Expose
|
||||
@SerializedName("refresh_token")
|
||||
private String refreshToken;
|
||||
|
||||
public boolean isCustomerTokenAlive(){
|
||||
long millis7days = 86400000 * 7;
|
||||
return (getTokenDeathDate(expiresIn).getTimeInMillis() - System.currentTimeMillis() >= millis7days);
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String getExpiresIn() {
|
||||
return expiresIn;
|
||||
}
|
||||
|
||||
public void setExpiresIn(String expiresIn) {
|
||||
this.expiresIn = expiresIn;
|
||||
}
|
||||
|
||||
public String getRefreshToken() {
|
||||
return refreshToken;
|
||||
}
|
||||
|
||||
public void setRefreshToken(String refreshToken) {
|
||||
this.refreshToken = refreshToken;
|
||||
}
|
||||
}
|
||||
69
app/src/main/java/ch/pizzalink/android/model/UserModel.java
Normal file
69
app/src/main/java/ch/pizzalink/android/model/UserModel.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package ch.pizzalink.android.model;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 26/09/2017.
|
||||
*/
|
||||
|
||||
public class UserModel {
|
||||
|
||||
@Expose
|
||||
@SerializedName("customer_id")
|
||||
private String id;
|
||||
|
||||
private String firstname;
|
||||
private String lastname;
|
||||
private String email;
|
||||
private String telephone;
|
||||
private CustomerTokenModel token;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public void setLastname(String lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getTelephone() {
|
||||
return telephone;
|
||||
}
|
||||
|
||||
public void setTelephone(String telephone) {
|
||||
this.telephone = telephone;
|
||||
}
|
||||
|
||||
public CustomerTokenModel getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(CustomerTokenModel token) {
|
||||
this.token = token;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package ch.pizzalink.android.model.responseModel;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 26/09/2017.
|
||||
*/
|
||||
|
||||
public class BaseResponseModel {
|
||||
|
||||
private boolean success;
|
||||
private String message;
|
||||
private int error_code;
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int getError_code() {
|
||||
return error_code;
|
||||
}
|
||||
|
||||
public void setError_code(int error_code) {
|
||||
this.error_code = error_code;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package ch.pizzalink.android.model.responseModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import ch.pizzalink.android.model.CategoryModel;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 26/09/2017.
|
||||
*/
|
||||
|
||||
public class CategoryResponseModel extends BaseResponseModel {
|
||||
|
||||
private ArrayList<CategoryModel> data;
|
||||
|
||||
public ArrayList<CategoryModel> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(ArrayList<CategoryModel> data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package ch.pizzalink.android.model.responseModel;
|
||||
|
||||
import ch.pizzalink.android.model.UserModel;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 26/09/2017.
|
||||
*/
|
||||
|
||||
public class LoginCustomerResponseModel extends BaseResponseModel {
|
||||
|
||||
private UserModel data;
|
||||
|
||||
public UserModel getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(UserModel data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
@@ -44,4 +44,11 @@
|
||||
<string name="fragment_title_item_beer_drinks">Beer</string>
|
||||
<string name="fragment_title_dessert">Dessert</string>
|
||||
|
||||
<string name="alert">Uyarı</string>
|
||||
<string name="error_message">Bir hata oluştu.</string>
|
||||
<string name="no_network_message">İnternet bağlanıtısı yok. Lütfen daha sonra tekrar deneyiniz.</string>
|
||||
<string name="bad_request">Bad Request</string>
|
||||
<string name="failed">Connection failed</string>
|
||||
<string name="ok">Tamam</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -16,6 +16,7 @@ allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven { url 'https://jitpack.io' }
|
||||
maven { url "https://maven.google.com" }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user