diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index 4726636..018d3fe 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -2,9 +2,16 @@ \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 7009329..9d76014 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -65,7 +65,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index b7a77b5..791f7f0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,42 @@ apply plugin: 'com.android.application' +apply plugin: 'jacoco-android' + +task jacocoCustomTestReport(type: JacocoReport, dependsOn: "testDebugUnitTest") { + println ":${project.name}:Generating Jacoco reports" + group = "Reporting" + description = "Generate Jacoco coverage reports" + + reports { + xml.enabled = true + csv.enabled = true + html.enabled = true + } + + def fileFilter = ['**/R.class', + '**/R$*.class', + '**/BuildConfig.*', + '**/Manifest*.*', + 'android/**/*.*', + '**/Lambda$*.class', //Retrolambda + '**/Lambda.class', + '**/*Lambda.class', + '**/*Lambda*.class', + '**/*Lambda*.*', + '**/*Builder.*', + '**/*_MembersInjector.class', //Dagger2 generated code + '**/*_MembersInjector*.*', //Dagger2 generated code + '**/*_*Factory*.*', //Dagger2 generated code + '**/*Component*.*', //Dagger2 generated code + '**/*Module*.*' //Dagger2 generated code + ] + def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter) + def mainSrc = "${project.projectDir}/src/main/java" + + sourceDirectories = files([mainSrc]) + classDirectories = files([debugTree]) + executionData = fileTree(dir: project.projectDir, includes: + ['**/*.exec' , '**/*.ec']) +} android { compileSdkVersion 26 @@ -40,6 +78,7 @@ android { } minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + testCoverageEnabled true } } } @@ -55,11 +94,18 @@ dependencies { compile 'com.android.support:recyclerview-v7:26.1.0' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.github.medyo:android-about-page:1.1.1' - compile 'com.android.support:design:23.0.0' + compile 'com.android.support:design:26.1.0' + compile 'com.android.support:support-v4:26.1.0' + compile 'com.github.bumptech.glide:glide:3.7.0' compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.squareup.retrofit2:retrofit:2.3.0' compile 'com.squareup.retrofit2:converter-gson:2.3.0' + compile 'com.squareup.retrofit2:converter-scalars:2.3.0' + + compile 'com.squareup.okhttp3:logging-interceptor:3.5.0' + compile 'com.squareup.retrofit2:converter-jackson:2.3.0' + testCompile 'junit:junit:4.12' testCompile 'org.json:json:20160810' compile 'com.google.code.gson:gson:2.8.2' @@ -68,6 +114,7 @@ dependencies { //Mockito (testing) testCompile 'org.mockito:mockito-core:2.7.22' androidTestCompile 'org.mockito:mockito-android:2.7.22' + compile 'com.squareup.retrofit2:retrofit-mock:2.3.0' // Espresso support androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { @@ -84,6 +131,10 @@ dependencies { compile 'com.google.firebase:firebase-ads:11.6.0' compile 'com.google.android.gms:play-services:11.6.0' + //mock server + androidTestCompile 'com.squareup.retrofit2:retrofit-mock:2.3.0' + androidTestCompile ('com.squareup.okhttp:mockwebserver:2.7.0') + } static def getDate() { diff --git a/app/src/androidTest/java/eu/jnksoftware/discountfinderandroid/ui/customer/MenuCustomerTest.java b/app/src/androidTest/java/eu/jnksoftware/discountfinderandroid/ui/customer/MenuCustomerTest.java index 7185e86..56ceb3f 100644 --- a/app/src/androidTest/java/eu/jnksoftware/discountfinderandroid/ui/customer/MenuCustomerTest.java +++ b/app/src/androidTest/java/eu/jnksoftware/discountfinderandroid/ui/customer/MenuCustomerTest.java @@ -18,7 +18,7 @@ public class MenuCustomerTest { - @Rule + /*@Rule public ActivityTestRule menuCustomerActivityTestRule = new ActivityTestRule<>(MenuCustomer.class); @Before @@ -51,5 +51,5 @@ public void testAboutButtonClick(){ @After public void tearDown() throws Exception { } - +*/ } \ No newline at end of file diff --git a/app/src/debug/res/values/google_maps_api.xml b/app/src/debug/res/values/google_maps_api.xml new file mode 100644 index 0000000..a2b6af9 --- /dev/null +++ b/app/src/debug/res/values/google_maps_api.xml @@ -0,0 +1,24 @@ + + + AIzaSyCnjNNPviOid3FOGAlKCZcjzD8IGrNX_B0 + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e8fa3e4..3bc70e7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,6 +5,7 @@ + + > @@ -25,16 +27,12 @@ - - - - - - - - + + + + @@ -43,7 +41,7 @@ - + @@ -56,15 +54,21 @@ - - + + + + + android:name=".services.ChooseStoreLocation" + android:label="@string/title_activity_choose_store_location" /> + \ No newline at end of file diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/ApiUtils.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/ApiUtils.java index a86a916..e7d3bda 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/ApiUtils.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/ApiUtils.java @@ -14,8 +14,11 @@ public static IuserService getMockUserService(){ return RetrofitClient.getClient(mockBaseUrl).create(IuserService.class); } - public static ShopsApiInterface getMockUserServiceShopsApi(){ - return RetrofitClient.getClient(mockBaseUrl).create(ShopsApiInterface.class); + public static String getBaseUrl() { + return baseUrl; } + public static String getMockBaseUrl() { + return mockBaseUrl; + } } diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/DiscountsApiInterface.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/DiscountsApiInterface.java deleted file mode 100644 index 4f07399..0000000 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/DiscountsApiInterface.java +++ /dev/null @@ -1,20 +0,0 @@ -package eu.jnksoftware.discountfinderandroid.Apis; - -import java.util.List; - -import eu.jnksoftware.discountfinderandroid.models.discounts.Discount; -import retrofit2.Call; -import retrofit2.http.Body; -import retrofit2.http.Header; -import retrofit2.http.Headers; -import retrofit2.http.POST; - - -public interface DiscountsApiInterface { - - @Headers({("Content-Type:application/json"),("Accept:application/json")}) - @POST("/api/user/findDiscounts") - Call> getDiscounts(@Body PostDiscount postDiscount, @Header("Authorization") String auth); - - -} diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/HttpCall.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/HttpCall.java new file mode 100644 index 0000000..529913d --- /dev/null +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/HttpCall.java @@ -0,0 +1,100 @@ +package eu.jnksoftware.discountfinderandroid.Apis; + +import android.widget.Toast; + +import com.google.gson.Gson; + +import eu.jnksoftware.discountfinderandroid.Utilities.ManageSharePrefs; +import eu.jnksoftware.discountfinderandroid.models.Location; +import eu.jnksoftware.discountfinderandroid.models.token.FcmToken; +import eu.jnksoftware.discountfinderandroid.models.token.User; +import eu.jnksoftware.discountfinderandroid.services.IuserService; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +/** + * Created by makis on 21/12/2017. + */ + +public class HttpCall { + private IuserService iuserService; + + public HttpCall() { + iuserService = ApiUtils.getUserService(); + } + + public int setFcmToken(FcmToken token, String auth){ + final int[] statusCode = new int[1]; + Call call =iuserService.registerFcmToken(token, auth); + call.enqueue(new Callback() { + + @Override + public void onResponse(retrofit2.Call call, Response response) { + statusCode[0] =response.code(); + } + + @Override + public void onFailure(retrofit2.Call call, Throwable t) { + } + + }); + return statusCode[0]; + } + + public int setUserLocation(Location location, String auth){ + final int[] statuscode = new int[1]; + ; + Call call =iuserService.setUserLocation(location, auth); + call.enqueue(new Callback() { + + @Override + public void onResponse(retrofit2.Call call, Response response) { + + + do { + statuscode[0] = response.code(); + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }while (statuscode[0] ==0); + } + + + @Override + public void onFailure(retrofit2.Call call, Throwable t) { + } + + }); + return statuscode[0]; + } + + public void refreshToken(){ + String refresh_token=" "; + User tempUser= ManageSharePrefs.readUser(""); + if (tempUser!=null){ + refresh_token=tempUser.getRefreshToken(); + } + Call call =iuserService.refreshAccessToken(refresh_token); + call.enqueue(new Callback() { + + @Override + public void onResponse(retrofit2.Call call, Response response) { + int statusCode =response.code(); + if (response.isSuccessful()){ + User user=response.body(); + ManageSharePrefs.writeUser(user); + } + } + + @Override + public void onFailure(retrofit2.Call call, Throwable t) { + } + + }); + + } + +} diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/RestClient.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/RestClient.java deleted file mode 100644 index c6c54e2..0000000 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/RestClient.java +++ /dev/null @@ -1,21 +0,0 @@ -package eu.jnksoftware.discountfinderandroid.Apis; - -import retrofit2.Retrofit; -import retrofit2.converter.gson.GsonConverterFactory; - - -public class RestClient { - - private static final String base_url = "http://83.212.117.108:9000/api/"; - private static Retrofit retrofit = null; - - public static Retrofit getClient(){ - if(retrofit == null){ - retrofit = new Retrofit.Builder() - .baseUrl(base_url) - .addConverterFactory(GsonConverterFactory.create()) - .build(); - } - return retrofit; - } -} diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/RetrofitClient.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/RetrofitClient.java index 4a23467..1448175 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/RetrofitClient.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/RetrofitClient.java @@ -1,5 +1,7 @@ package eu.jnksoftware.discountfinderandroid.Apis; +import okhttp3.OkHttpClient; +import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; @@ -7,10 +9,17 @@ public class RetrofitClient { private static Retrofit retrofit=null; public static Retrofit getClient(String url){ + HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); + interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); + OkHttpClient client = new OkHttpClient.Builder() + .addInterceptor(interceptor).build(); + if(retrofit==null){ + retrofit=new Retrofit.Builder() .baseUrl(url) .addConverterFactory(GsonConverterFactory.create()) + .client(client) .build(); } return retrofit; } diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/ShopsApiInterface.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/ShopsApiInterface.java deleted file mode 100644 index 408a5c4..0000000 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/Apis/ShopsApiInterface.java +++ /dev/null @@ -1,61 +0,0 @@ -package eu.jnksoftware.discountfinderandroid.Apis; - -import java.util.List; - -import eu.jnksoftware.discountfinderandroid.models.SellerDiscount; -import eu.jnksoftware.discountfinderandroid.models.Shop; -import eu.jnksoftware.discountfinderandroid.models.discounts.DiscountGet; -import eu.jnksoftware.discountfinderandroid.models.discounts.DiscountPost; -import retrofit2.Call; -import retrofit2.http.Body; -import retrofit2.http.DELETE; -import retrofit2.http.GET; -import retrofit2.http.Header; -import retrofit2.http.Headers; -import retrofit2.http.POST; -import retrofit2.http.PUT; -import retrofit2.http.Path; -import retrofit2.http.Query; - -public interface ShopsApiInterface { - - @GET("shop") - Call> getShopsList(); - - @GET ("shop/") - Call> getShopWithId(@Query("id") int id); - - @GET ("user/shop") - Call> getUserShops(); - - @GET ("user/shop/") - Call> getUserShopWithId(@Query("id") int id); - - @Headers({("Content-Type:application/json"),("Accept:application/json")}) - @GET ("user/shop/") - Call> getUserShops(@Header("Authorization") String auth); - - @Headers({("Content-Type:application/json"),("Accept:application/json")}) - @POST("shop") - Call addShop(@Body PostShop postShop, @Header("Authorization") String auth); - - @Headers({("Content-Type:application/json"),("Accept:application/json")}) - @DELETE("shop/{id}") - Call deleteShop(@Path("id") int id, @Header("Authorization") String auth); - - @Headers({("Content-Type:application/json"),("Accept:application/json")}) - @PUT("shop") - Call updateShop(@Body UpdatePostShop updatePostShop, @Header("Authorization") String auth); - - @Headers({("Content-Type:application/json"),("Accept:application/json")}) - @POST("discount") - Call addDiscount(@Body DiscountPost discountPost, @Header("Authorization") String auth); - - @Headers({("Content-Type:application/json"),("Accept:application/json")}) - @GET("discount") - Call> getSellerDiscounts(@Header("Authorization") String auth); - - @Headers({("Content-Type:application/json"),("Accept:application/json")}) - @DELETE("discount/{id}") - Call deleteSellerDiscount(@Path("id") int id,@Header("Authorization") String auth); -} diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/CustomerMenu.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/CustomerMenu.java new file mode 100644 index 0000000..97add5a --- /dev/null +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/CustomerMenu.java @@ -0,0 +1,196 @@ +package eu.jnksoftware.discountfinderandroid; + +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.support.annotation.NonNull; +import android.support.design.widget.NavigationView; +import android.support.v4.app.FragmentManager; +import android.support.v4.view.GravityCompat; +import android.support.v4.widget.DrawerLayout; +import android.support.v7.app.ActionBarDrawerToggle; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.TextView; +import android.widget.Toast; + +import eu.jnksoftware.discountfinderandroid.Utilities.ManageSharePrefs; +import eu.jnksoftware.discountfinderandroid.models.token.User; +import eu.jnksoftware.discountfinderandroid.services.GeoLocation; +import eu.jnksoftware.discountfinderandroid.ui.customer.MenuCustomer; +import eu.jnksoftware.discountfinderandroid.ui.customer.recyclers.DiscountCustomerRecyclerList; +import eu.jnksoftware.discountfinderandroid.ui.customer.shops.SellerShops; +import eu.jnksoftware.discountfinderandroid.ui.customer.userPreferences.UserPreferenceList; +import eu.jnksoftware.discountfinderandroid.ui.general.AboutUs; +import eu.jnksoftware.discountfinderandroid.ui.general.Settings; + +public class CustomerMenu extends AppCompatActivity + implements NavigationView.OnNavigationItemSelectedListener { + + private String auth; + private User user; + private GeoLocation location; + private boolean doubleBackPress; + private TextView navHeaderEmail; + private TextView navHeaderName; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_customer_menu); + Toolbar toolbar = findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + DrawerLayout drawer = findViewById(R.id.drawer_layout); + ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( + this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); + drawer.addDrawerListener(toggle); + toggle.syncState(); + + NavigationView navigationView = findViewById(R.id.nav_view); + navigationView.setNavigationItemSelectedListener(this); + + boolean isSellerChecked = ManageSharePrefs.readUserIsSeller(false); + MenuItem item = navigationView.getMenu().getItem(2); + item.setVisible(isSellerChecked); + + user = ManageSharePrefs.readUser( null); + auth = "Bearer " + user.getAccessToken(); + location = new GeoLocation(this); + + Bundle bundle = new Bundle(); + bundle.putString("auth", auth); + MenuCustomer customerFragment = new MenuCustomer(); + customerFragment.setArguments(bundle); + FragmentManager manager = getSupportFragmentManager(); + manager.beginTransaction().replace(R.id.customerMenuConstraintLayout,customerFragment + ,customerFragment.getTag()) + .commit(); + } + + @Override + public void onBackPressed() { + DrawerLayout drawer = findViewById(R.id.drawer_layout); + if (drawer.isDrawerOpen(GravityCompat.START)) { + drawer.closeDrawer(GravityCompat.START); + } else { + checkDoubleBackPress(); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.customer_menu, menu); + navHeaderEmail = findViewById(R.id.tvNavHeaderUserEmail); + navHeaderName = findViewById(R.id.tvNavHeaderUserName); + setUpNavHeaderInfo(getIntent().getStringExtra("email"),"Kostas"); + + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //noinspection SimplifiableIfStatement + if (id == R.id.action_settings) { + return true; + } + + return super.onOptionsItemSelected(item); + } + + @SuppressWarnings("StatementWithEmptyBody") + @Override + public boolean onNavigationItemSelected(@NonNull MenuItem item) { + // Handle navigation view item clicks here. + int id = item.getItemId(); + + if (id == R.id.nav_home) { + Bundle bundle = new Bundle(); + bundle.putString("auth", auth); + MenuCustomer customerFragment = new MenuCustomer(); + customerFragment.setArguments(bundle); + FragmentManager manager = getSupportFragmentManager(); + manager.beginTransaction().replace(R.id.customerMenuConstraintLayout,customerFragment + ,customerFragment.getTag()) + .commit(); + } else if (id == R.id.nav_offers) { + Bundle bundle = new Bundle(); + bundle.putString("auth", auth); + bundle.putString("lat", String.valueOf(location.getLatitude())); + bundle.putString("lon", String.valueOf(location.getLongitude())); + DiscountCustomerRecyclerList discountsFragment = new DiscountCustomerRecyclerList(); + discountsFragment.setArguments(bundle); + FragmentManager manager = getSupportFragmentManager(); + manager.beginTransaction().replace(R.id.customerMenuConstraintLayout,discountsFragment + ,discountsFragment.getTag()) + .commit(); + + }else if (id == R.id.nav_seller_shops){ + Bundle bundle = new Bundle(); + bundle.putString("auth", auth); + SellerShops sellerShopsFragment= new SellerShops(); + sellerShopsFragment.setArguments(bundle); + FragmentManager manager = getSupportFragmentManager(); + manager.beginTransaction().replace(R.id.customerMenuConstraintLayout,sellerShopsFragment + ,sellerShopsFragment.getTag()) + .commit(); + } else if (id == R.id.nav_preferences) { + Bundle bundle = new Bundle(); + bundle.putString("auth", auth); + UserPreferenceList preferenceFragment= new UserPreferenceList(); + preferenceFragment.setArguments(bundle); + FragmentManager manager = getSupportFragmentManager(); + manager.beginTransaction().replace(R.id.customerMenuConstraintLayout,preferenceFragment + ,preferenceFragment.getTag()) + .commit(); + } + //show form with intent + else if (id == R.id.nav_settings) { + startActivity(new Intent(getBaseContext(),Settings.class)); + } else if(id == R.id.nav_about){ + startActivity(new Intent(getBaseContext(), AboutUs.class)); + } + else if(id == R.id.nav_logout) { + + } + + DrawerLayout drawer = findViewById(R.id.drawer_layout); + drawer.closeDrawer(GravityCompat.START); + return true; + } + + private void checkDoubleBackPress(){ + if (doubleBackPress) { + Intent intent = new Intent(Intent.ACTION_MAIN); + intent.addCategory(Intent.CATEGORY_HOME); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivity(intent); + finish(); + System.exit(0); + } + doubleBackPress = true; + + Toast.makeText(getBaseContext(),"Please press BACK again to exit",Toast.LENGTH_LONG).show(); + new Handler().postDelayed(new Runnable(){ + @Override + public void run(){ + doubleBackPress = false; + + } + }, 3000); + doubleBackPress = true; + } + + private void setUpNavHeaderInfo(String email,String name) { + this.navHeaderEmail.setText(email); + this.navHeaderName.setText(name); + } +} diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/Utilities/ManageSharePrefs.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/Utilities/ManageSharePrefs.java new file mode 100644 index 0000000..fd65a68 --- /dev/null +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/Utilities/ManageSharePrefs.java @@ -0,0 +1,131 @@ +package eu.jnksoftware.discountfinderandroid.Utilities; + +import android.app.Activity; +import android.content.Context; +import android.content.SharedPreferences; + +import com.google.gson.Gson; + +import eu.jnksoftware.discountfinderandroid.models.Location; +import eu.jnksoftware.discountfinderandroid.models.token.User; + + +public class ManageSharePrefs { + + private static SharedPreferences mSharedPref; + + + private ManageSharePrefs() { + + } + + public static void init(Context context) { + if (mSharedPref == null) + mSharedPref = context.getSharedPreferences(context.getPackageName(), Activity.MODE_PRIVATE); + } + + public static User readUser(String defValue) { + User tempUser; + if (mSharedPref.contains("userData")) { + String userToString = mSharedPref.getString("userData", defValue); + Gson userJson = new Gson(); + tempUser = userJson.fromJson(userToString, User.class); + } else { + tempUser = null; + } + + return tempUser; + } + + public static void writeUser(User user) { + SharedPreferences.Editor prefsEditor = mSharedPref.edit(); + Gson userJson = new Gson(); + String userString = userJson.toJson(user); + prefsEditor.putString("userData", userString); + prefsEditor.commit(); + } + + public static void writeFcmTokenData(String fcmData) { + SharedPreferences.Editor prefsEditor = mSharedPref.edit(); + prefsEditor.putString("fcmUSerData", fcmData); + prefsEditor.commit(); + + } + + public static String readFcmTokenData(String defValue) { + String tempFcmData; + + if (mSharedPref.contains("fcmUserDate")) { + tempFcmData = mSharedPref.getString("fcmUSerData", defValue); + } else { + tempFcmData = " "; + } + + return tempFcmData; + + } + + public static void writeLocation(Location location) { + Gson userJson = new Gson(); + String locationToString = userJson.toJson(location); + SharedPreferences.Editor prefsEditor = mSharedPref.edit(); + prefsEditor.putString("userLocation", locationToString); + prefsEditor.commit(); + + } + + public static Location readLocation(String defValue) { + Location myTempLocation; + + if (mSharedPref.contains("userLocation")) { + String locationToString = mSharedPref.getString("userLocation", defValue); + Gson userJson = new Gson(); + myTempLocation = userJson.fromJson(locationToString, Location.class); + } else { + myTempLocation = null; + } + + return myTempLocation; + } + + /* public static UserTokenRequest readUserAccount(String defValue) { + UserTokenRequest userTokenRequest; + if (mSharedPref.contains("userAccount")) { + String userAccountToString = mSharedPref.getString("userAccount", defValue); + Gson userAccountJson = new Gson(); + userTokenRequest = userAccountJson.fromJson(userAccountToString, UserTokenRequest.class); + } else { + userTokenRequest = null; + } + + return userTokenRequest; + }*/ + + /* public static void writeUserAccount(UserTokenRequest userTokenRequest) { + SharedPreferences.Editor prefsEditor = mSharedPref.edit(); + Gson userAccountJson = new Gson(); + String userAccountToString = userAccountJson.toJson(userTokenRequest); + prefsEditor.putString("userData", userAccountToString ); + prefsEditor.commit(); + }*/ + + public static boolean readUserIsSeller(Boolean defValue) { + Boolean isSeller; + if (mSharedPref.contains("userIsSeller")) { + isSeller = mSharedPref.getBoolean("userIsSeller", defValue); + } else { + isSeller=false; + } + + return isSeller; + } + + public static void writeUserIsSeller(Boolean value) { + SharedPreferences.Editor prefsEditor = mSharedPref.edit(); + prefsEditor.putBoolean("userIsSeller", value ); + prefsEditor.commit(); + } + + + +} diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/Location.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/Location.java index 7f75c97..7c40358 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/Location.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/Location.java @@ -1,38 +1,39 @@ package eu.jnksoftware.discountfinderandroid.models; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + public class Location { - private double latitude; - private double longitude; + @SerializedName("logPos") + @Expose + private double logPos; + @SerializedName("latPos") + @Expose + private double latPos; public Location() { - latitude = 0; - longitude = 0; } - public Location(android.location.Location location) { - latitude = location.getLatitude(); - longitude = location.getLongitude(); + public Location(double logPos, double latPos) { + this.logPos = logPos; + this.latPos = latPos; } - public Location(double latitude, double longitude) { - this.latitude = latitude; - this.longitude = longitude; + public double getLogPos() { + return logPos; } - public double getLatitude() { - return latitude; + public void setLogPos(double logPos) { + this.logPos = logPos; } - public void setLatitude(double latitude) { - this.latitude = latitude; + public double getLatPos() { + return latPos; } - public double getLongitude() { - return longitude; + public void setLatPos(double latPos) { + this.latPos = latPos; } - public void setLongitude(double longitude) { - this.longitude = longitude; - } } diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/Shop.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/Shop.java index 942a927..3866bf4 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/Shop.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/Shop.java @@ -19,8 +19,8 @@ public Shop(int id,int ownerId,String brandName, Location location) { public Uri getMapsUri() { - Double Latitude = location.getLatitude(); - Double Longitude = location.getLongitude(); + Double Latitude = location.getLatPos(); + Double Longitude = location.getLogPos(); String labelLocation = "x-Team Sample : " + ownerId; return Uri.parse( diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/User.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/User.java deleted file mode 100644 index a519e92..0000000 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/User.java +++ /dev/null @@ -1,36 +0,0 @@ -package eu.jnksoftware.discountfinderandroid.models; - - -public class User{ - - private String tokenType; - private String refreshToken; - private String expireToken; - private String accessToken; - - - public String getAccessToken() {return accessToken;} - - public void setAccessToken(String accessToken) {this.accessToken = accessToken;} - - public String getTokenType() {return tokenType;} - - public void setTokenType(String tokenType) {this.tokenType = tokenType;} - - public String getRefreshToken() { - return refreshToken; - } - - public void setRefreshToken(String refreshToken) { - this.refreshToken = refreshToken; - } - - public String getExpireToken() { - return expireToken; - } - - public void setExpireToken(String expireToken) { - this.expireToken = expireToken; - } - -} diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/discountPreferences/DiscountPreferencesResponse.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/discountPreferences/DiscountPreferencesResponse.java index 64fe284..bbba433 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/discountPreferences/DiscountPreferencesResponse.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/discountPreferences/DiscountPreferencesResponse.java @@ -16,13 +16,11 @@ public class DiscountPreferencesResponse { private Integer category; @SerializedName("price") @Expose - private Integer price; + private float price; @SerializedName("tags") @Expose private String tags; - @SerializedName("image") - @Expose - private String image; + @SerializedName("categoryTitle") @Expose private String categoryTitle; @@ -47,7 +45,7 @@ public void setCategory(Integer category) { this.category = category; } - public Integer getPrice() { + public float getPrice() { return price; } @@ -63,9 +61,7 @@ public void setTags(String tags) { this.tags = tags; } - public String getImage() { - return image; - } + public String getCategoryTitle() { return categoryTitle; diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/discounts/Discount.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/discounts/Discount.java index d270aeb..da29127 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/discounts/Discount.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/discounts/Discount.java @@ -2,30 +2,34 @@ public class Discount { - private int id; + private int discountId; private String category; private String shortDescription; private String shopName; private float finalPrice; - private String productImageUrl; + private String productImageURL; private double distance; + private double shopLatPos; + private double shopLogPos; - public Discount(int id , String category, String shortDescription, String shopName, float finalPrice, String productImageUrl,double distance) { - this.id = id; + public Discount(int discountId , String category, String shortDescription, String shopName, float finalPrice, String productImageURL,double distance, double shopLogPos, double shopLatPos) { + this.discountId = discountId; this.category = category; this.shortDescription = shortDescription; this.shopName = shopName; this.finalPrice = finalPrice; - this.productImageUrl = productImageUrl; + this.productImageURL = productImageURL; this.distance = distance; + this.shopLatPos = shopLatPos; + this.shopLogPos = shopLogPos; } - public int getId() { - return id; + public int getDiscountId() { + return discountId; } - public void setId(int id) { - this.id = id; + public void setid(int id) { + this.discountId = discountId; } public String getShortDescription() { @@ -52,12 +56,12 @@ public void setFinalPrice(float finalPrice) { this.finalPrice = finalPrice; } - public String getProductImageUrl() { - return productImageUrl; + public String getProductImageURL() { + return productImageURL; } - public void setProductImageUrl(String productImage) { - this.productImageUrl = productImageUrl; + public void setProductImageURL(String productImage) { + this.productImageURL = productImageURL; } public String getCategory() { @@ -75,4 +79,12 @@ public double getDistance() { public void setDistance(double distance) { this.distance = distance; } + + public double getShopLatPos() { + return shopLatPos; + } + + public double getShopLogPos() { + return shopLogPos; + } } diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/discounts/DiscountPost.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/discounts/DiscountPost.java index d14dbd8..3149366 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/discounts/DiscountPost.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/discounts/DiscountPost.java @@ -5,6 +5,10 @@ import com.google.gson.annotations.SerializedName; public class DiscountPost { + @SerializedName("shopId") + @Expose + private int shopId; + @SerializedName("category") @Expose private int category; @@ -21,15 +25,68 @@ public class DiscountPost { @Expose private String description; - @SerializedName("image") + @SerializedName("imageBase") + @Expose + private String imageBase; + + @SerializedName("imageTitle") @Expose - private String image; + private String imageTitle; + + public int getShopId() { + + return shopId; + } + + public void setShopId(int shopId) { + this.shopId = shopId; + } + + public int getCategory() { + return category; + } - public DiscountPost(int category, double originalPrice, double currentPrice, String description, String image) { + public void setCategory(int category) { this.category = category; + } + + public double getOriginalPrice() { + return originalPrice; + } + + public void setOriginalPrice(double originalPrice) { this.originalPrice = originalPrice; + } + + public double getCurrentPrice() { + return currentPrice; + } + + public void setCurrentPrice(double currentPrice) { this.currentPrice = currentPrice; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { this.description = description; - this.image = image; + } + + public String getImageBase() { + return imageBase; + } + + public void setImageBase(String imageBase) { + this.imageBase = imageBase; + } + + public String getImageTitle() { + return imageTitle; + } + + public void setImageTitle(String imageTitle) { + this.imageTitle = imageTitle; } } diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/discounts/TopDiscount.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/discounts/TopDiscount.java new file mode 100644 index 0000000..e446697 --- /dev/null +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/discounts/TopDiscount.java @@ -0,0 +1,26 @@ +package eu.jnksoftware.discountfinderandroid.models.discounts; + + +public class TopDiscount { + private String shopName; + private String category; + private String shortDescription; + private int finalPrice; + private String productImageURL; + private int discountId; + private double shopLatPos; + private double shopLogPos; + + public TopDiscount(String shortDescription, String productImage) { + this.shortDescription = shortDescription; + this.productImageURL = productImage; + } + + public String getShortDescription() { + return shortDescription; + } + + public String getProductImage() { + return productImageURL; + } +} diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/token/FcmToken.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/token/FcmToken.java new file mode 100644 index 0000000..6259aa9 --- /dev/null +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/token/FcmToken.java @@ -0,0 +1,26 @@ +package eu.jnksoftware.discountfinderandroid.models.token; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * Created by makis on 21/12/2017. + */ + +public class FcmToken { + @SerializedName("deviceToken") + @Expose + private String deviceToken; + + public FcmToken(String deviceToken) { + this.deviceToken = deviceToken; + } + + public String getDeviceToken() { + return deviceToken; + } + + public void setDeviceToken(String deviceToken) { + this.deviceToken = deviceToken; + } +} diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/token/RegisterTokenRequest.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/token/RegisterTokenRequest.java deleted file mode 100644 index 18b4842..0000000 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/token/RegisterTokenRequest.java +++ /dev/null @@ -1,52 +0,0 @@ -package eu.jnksoftware.discountfinderandroid.models.token; - -import com.google.gson.annotations.Expose; -import com.google.gson.annotations.SerializedName; - - -public class RegisterTokenRequest { - @SerializedName("firstName") - @Expose - private String firstName; - @SerializedName("lastName") - @Expose - private String lastName; - @SerializedName("eMail") - @Expose - private String eMail; - @SerializedName("password") - @Expose - private String password; - - 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 getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } -} diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/token/UserTokenResponse.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/token/User.java similarity index 80% rename from app/src/main/java/eu/jnksoftware/discountfinderandroid/models/token/UserTokenResponse.java rename to app/src/main/java/eu/jnksoftware/discountfinderandroid/models/token/User.java index 3c80b56..0023c22 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/token/UserTokenResponse.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/token/User.java @@ -4,7 +4,7 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; -public class UserTokenResponse { +public class User { @SerializedName("token_type") @Expose @@ -43,4 +43,11 @@ public String getRefreshToken() { return refreshToken; } + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + + public void setRefreshToken(String refreshToken) { + this.refreshToken = refreshToken; + } } diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/token/UserTokenRequest.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/token/UserTokenRequest.java deleted file mode 100644 index 11ed5e3..0000000 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/models/token/UserTokenRequest.java +++ /dev/null @@ -1,24 +0,0 @@ -package eu.jnksoftware.discountfinderandroid.models.token; - - -public class UserTokenRequest { - private String username; - private String password; - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } -} - diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/ChooseStoreLocation.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/ChooseStoreLocation.java new file mode 100644 index 0000000..2644aef --- /dev/null +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/ChooseStoreLocation.java @@ -0,0 +1,171 @@ +package eu.jnksoftware.discountfinderandroid.services; + +import android.Manifest; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.location.Address; +import android.location.Geocoder; +import android.support.v4.app.ActivityCompat; +import android.support.v4.app.FragmentActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.google.android.gms.maps.CameraUpdateFactory; +import com.google.android.gms.maps.GoogleMap; +import com.google.android.gms.maps.OnMapReadyCallback; +import com.google.android.gms.maps.SupportMapFragment; +import com.google.android.gms.maps.model.LatLng; +import com.google.android.gms.maps.model.MarkerOptions; + +import java.io.IOException; +import java.util.List; +import java.util.Locale; + +import eu.jnksoftware.discountfinderandroid.R; +import eu.jnksoftware.discountfinderandroid.models.Location; + +public class ChooseStoreLocation extends FragmentActivity implements OnMapReadyCallback { + + private GoogleMap mMap; + LatLng currentLatLng; + Location userLocation = new Location(); + boolean hasMarker = false; + String auth; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_choose_store_location); + SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() + .findFragmentById(R.id.map); + mapFragment.getMapAsync(this); + } + + @Override + public void onMapReady(final GoogleMap googleMap) { + Button searchButton = findViewById(R.id.searchBtn); + searchButton.setOnClickListener(searchClick); + mMap = googleMap; + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + // TODO: Consider calling + // ActivityCompat#requestPermissions + // here to request the missing permissions, and then overriding + // public void onRequestPermissionsResult(int requestCode, String[] permissions, + // int[] grantResults) + // to handle the case where the user grants the permission. See the documentation + // for ActivityCompat#requestPermissions for more details. + return; + } + mMap.setMyLocationEnabled(true); + initializeMapTypes(); + userLocation.setLogPos(getIntent().getDoubleExtra("lat", 100)); + userLocation.setLatPos(getIntent().getDoubleExtra("lon", 100)); + auth = getIntent().getStringExtra("auth"); + currentLatLng = new LatLng(userLocation.getLogPos(),userLocation.getLatPos()); + mMap.animateCamera(CameraUpdateFactory.newLatLng(currentLatLng)); + mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng, 13)); + mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() { + @Override + public void onMapClick(LatLng latLng) { + checkMarkers(latLng); + Intent intent = getIntent(); + intent.putExtra("streetName",getStreetName(getBaseContext(),latLng)); + intent.putExtra("storeLat",latLng.latitude); + intent.putExtra("storeLon",latLng.longitude); + intent.putExtra("lat",userLocation.getLatPos()); + intent.putExtra("lon",userLocation.getLogPos()); + intent.putExtra("auth",auth); + setResult(RESULT_OK,intent); + finish(); + } + }); + } + + private final View.OnClickListener searchClick = new View.OnClickListener() { + @Override + public void onClick(View v) { + EditText searchEditText = findViewById(R.id.searchEditText); + String searchLocation = searchEditText.getText().toString(); + List
addresses = null; + if(searchLocation!=null && !searchLocation.equals("")) { + Geocoder geocoder = new Geocoder(getBaseContext()); + try { + addresses = geocoder.getFromLocationName(searchLocation, 1); + } catch (IOException e) { + e.printStackTrace(); + } + if (addresses.isEmpty()) { + Toast.makeText(ChooseStoreLocation.this,"There is no place with this name",Toast.LENGTH_SHORT).show(); + } else { + Address address = addresses.get(0); + LatLng latLng = new LatLng(address.getLatitude(), address.getLongitude()); + mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng)); + checkMarkers(latLng); + addresses.remove(0); + } + } + else Toast.makeText(ChooseStoreLocation.this,"Insert a valid place",Toast.LENGTH_SHORT).show(); + } + }; + + private void initializeMapTypes(){ + Button sateliteButton = findViewById(R.id.sateliteBtn); + sateliteButton.setOnClickListener(sateliteClickListener); + if(mMap.getMapType() == GoogleMap.MAP_TYPE_SATELLITE){ + sateliteButton.setText("Terrain"); + } + else{ + sateliteButton.setText("Satelite"); + } + + } + + private final View.OnClickListener sateliteClickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + if (mMap.getMapType() == GoogleMap.MAP_TYPE_SATELLITE) { + mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN); + } else { + mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); + } + initializeMapTypes(); + } + }; + + public void checkMarkers(LatLng latLng){ + if (!hasMarker) { + mMap.addMarker(createMarker(latLng)); + hasMarker = true; + } else { + mMap.clear(); + mMap.addMarker(createMarker(latLng)); + } + } + + public String getStreetName(Context context, LatLng latLng){ + Geocoder geocoder = new Geocoder(context, Locale.getDefault()); + double lat = latLng.latitude; + double lon = latLng.longitude; + try { + List
addresses = geocoder.getFromLocation(lat,lon,1); + Address address = addresses.get(0); + String name = address.getFeatureName(); + return name; + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + public MarkerOptions createMarker(LatLng latLng){ + MarkerOptions markerOptions = new MarkerOptions(); + String formattedLatLng = latLng.toString().substring(0, 4); + markerOptions.position(latLng).title(formattedLatLng); + return markerOptions; + } + +} diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/ChooseStoreLocationActivity.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/ChooseStoreLocationActivity.java deleted file mode 100644 index 617480f..0000000 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/ChooseStoreLocationActivity.java +++ /dev/null @@ -1,76 +0,0 @@ -package eu.jnksoftware.discountfinderandroid.services; - -import android.os.Bundle; -import android.support.v4.app.FragmentActivity; - -import com.google.android.gms.maps.CameraUpdateFactory; -import com.google.android.gms.maps.GoogleMap; -import com.google.android.gms.maps.OnMapReadyCallback; -import com.google.android.gms.maps.SupportMapFragment; -import com.google.android.gms.maps.model.CircleOptions; -import com.google.android.gms.maps.model.LatLng; -import com.google.android.gms.maps.model.MarkerOptions; - -import eu.jnksoftware.discountfinderandroid.R; - - -public class ChooseStoreLocationActivity extends FragmentActivity implements OnMapReadyCallback { - - private GoogleMap mMap; - LatLng currentLatLng; - boolean hasMarker = false; - - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_choose_store_location); - SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() - .findFragmentById(R.id.map); - mapFragment.getMapAsync(this); - } - - @Override - public void onMapReady(final GoogleMap googleMap) { - mMap = googleMap; - double lat = getIntent().getDoubleExtra("lat", 100); - double lon = getIntent().getDoubleExtra("lon", 100); - currentLatLng = new LatLng(lat, lon); - mMap.animateCamera(CameraUpdateFactory.newLatLng(currentLatLng)); - mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng, 13)); - mMap.addCircle(customizeCircle(1000,currentLatLng)); - mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() { - @Override - public void onMapClick(LatLng latLng) { - checkMarkers(latLng); - } - }); - } - - public void checkMarkers(LatLng latLng){ - if (!hasMarker) { - mMap.addMarker(createMarker(latLng)); - hasMarker = true; - } else { - mMap.clear(); - mMap.addCircle(customizeCircle(1000,currentLatLng)); - mMap.addMarker(createMarker(latLng)); - } - } - - public MarkerOptions createMarker(LatLng latLng){ - MarkerOptions markerOptions = new MarkerOptions(); - String formattedLatLng = latLng.toString().substring(0, 4); - markerOptions.position(latLng).title(formattedLatLng); - return markerOptions; - } - - public CircleOptions customizeCircle(double radius,LatLng latLng){ - CircleOptions circleOptions = new CircleOptions(); - circleOptions.center(latLng); - circleOptions.fillColor(R.color.cast_intro_overlay_button_background_color); - circleOptions.visible(true); - circleOptions.radius(radius); - return circleOptions; - } -} diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/GeoLocation.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/GeoLocation.java index 9a724ac..f865a48 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/GeoLocation.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/GeoLocation.java @@ -12,6 +12,10 @@ import android.os.Bundle; import android.os.IBinder; +import eu.jnksoftware.discountfinderandroid.Apis.HttpCall; +import eu.jnksoftware.discountfinderandroid.Utilities.ManageSharePrefs; +import eu.jnksoftware.discountfinderandroid.models.token.User; + public class GeoLocation extends Service implements LocationListener { @@ -23,8 +27,8 @@ public class GeoLocation extends Service implements LocationListener { private double latitude; private double longitude; - private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; - private static final long MIN_TIME_BW_UPDATES = 1000; // 1 minute + private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 50; // update after 50meters update + private static final long MIN_TIME_BW_UPDATES = 0; // don't update with time interval private LocationManager locationManager; @@ -140,7 +144,17 @@ public boolean canGetLocation() { @Override public void onLocationChanged(Location location) { + + User tempuser; + tempuser= ManageSharePrefs.readUser( null); + if (tempuser!=null) { + eu.jnksoftware.discountfinderandroid.models.Location myLocation = new eu.jnksoftware.discountfinderandroid.models.Location(location.getLongitude(), location.getLatitude()); + HttpCall httpCall = new HttpCall(); + int codesesponse = httpCall.setUserLocation(myLocation, tempuser.getTokenType() + " " + tempuser.getAccessToken()); + ManageSharePrefs.writeLocation(myLocation); + } this.location = location; + } diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/IuserService.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/IuserService.java index 16e264c..87f8b22 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/IuserService.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/IuserService.java @@ -2,16 +2,26 @@ import java.util.List; +import eu.jnksoftware.discountfinderandroid.Apis.PostShop; +import eu.jnksoftware.discountfinderandroid.Apis.UpdatePostShop; import eu.jnksoftware.discountfinderandroid.models.Category; +import eu.jnksoftware.discountfinderandroid.models.Location; +import eu.jnksoftware.discountfinderandroid.models.SellerDiscount; +import eu.jnksoftware.discountfinderandroid.models.Shop; import eu.jnksoftware.discountfinderandroid.models.discountPreferences.DiscountPreferencesPostResponse; import eu.jnksoftware.discountfinderandroid.models.discountPreferences.DiscountPreferencesRequest; import eu.jnksoftware.discountfinderandroid.models.discountPreferences.DiscountPreferencesResponse; -import eu.jnksoftware.discountfinderandroid.models.token.RegisterTokenRequest; -import eu.jnksoftware.discountfinderandroid.models.token.UserTokenRequest; -import eu.jnksoftware.discountfinderandroid.models.token.UserTokenResponse; +import eu.jnksoftware.discountfinderandroid.models.discounts.Discount; +import eu.jnksoftware.discountfinderandroid.models.discounts.DiscountGet; +import eu.jnksoftware.discountfinderandroid.models.discounts.DiscountPost; +import eu.jnksoftware.discountfinderandroid.models.discounts.TopDiscount; +import eu.jnksoftware.discountfinderandroid.models.token.FcmToken; +import eu.jnksoftware.discountfinderandroid.models.token.User; import retrofit2.Call; import retrofit2.http.Body; import retrofit2.http.DELETE; +import retrofit2.http.Field; +import retrofit2.http.FormUrlEncoded; import retrofit2.http.GET; import retrofit2.http.Header; import retrofit2.http.Headers; @@ -22,11 +32,13 @@ public interface IuserService { + @FormUrlEncoded @POST("login") - Call getTokenAcess(@Body UserTokenRequest userTokenRequest); + Call login(@Field("username")String username,@Field("password")String password); + @FormUrlEncoded @POST("register") - Call register(@Body RegisterTokenRequest registerTokenRequest); + Call register(@Field("firstName")String firstName,@Field("lastName")String lastName,@Field("eMail")String eMail,@Field("password")String password); @PUT("requestedDiscount/{id}") Call putDiscountPreferences(@Path("id")int id,@Body DiscountPreferencesRequest discountPreferencesRequest,@Header("Authorization") String auth); @@ -37,6 +49,7 @@ public interface IuserService { @GET("requestedDiscount/") Call getOneDiscountPreference(@Query("id")int id); + @Headers({("Content-Type:application/json"),("Accept:application/json")}) @GET("requestedDiscount") Call>getDiscountsPreference(@Header("Authorization")String auth); @@ -47,6 +60,69 @@ public interface IuserService { @GET("category") Call> fetchCategories(); + @GET("/api/discount/find/{distance}") + Call> getDiscounts(@Path("distance") int distance , @Header("Authorization") String auth); + + @GET("/api/discount/top/{distance}") + Call> getTopDiscounts(@Path("distance") int distance , @Header("Authorization") String auth); + + @Headers({("Content-Type:application/json"),("Accept:application/json")}) + @DELETE("shop/{id}") + Call deleteShop(@Path("id") int id, @Header("Authorization") String auth); + + @GET("shop") + Call> getShopsList(); + + @GET ("shop/") + Call> getShopWithId(@Query("id") int id); + + @GET ("user/shop") + Call> getUserShops(); + + @GET ("user/shop/") + Call> getUserShopWithId(@Query("id") int id); + + @Headers({("Content-Type:application/json"),("Accept:application/json")}) + @GET ("user/shop/") + Call> getUserShops(@Header("Authorization") String auth); + + @Headers({("Content-Type:application/json"),("Accept:application/json")}) + @POST("shop") + Call addShop(@Body PostShop postShop, @Header("Authorization") String auth); + + + + @Headers({("Content-Type:application/json"),("Accept:application/json")}) + @PUT("shop") + Call updateShop(@Body UpdatePostShop updatePostShop, @Header("Authorization") String auth); + + + @Headers({("Content-Type:application/json"),("Accept:application/json")}) + @POST("discount") + Call addDiscount(@Body DiscountPost discountPost, @Header("Authorization") String auth); + + @Headers({("Content-Type:application/json"),("Accept:application/json")}) + @GET("user/shop/{id}/discounts") + Call> getSellerDiscounts(@Path("id") int shopId,@Header("Authorization") String auth); + + @Headers({("Content-Type:application/json"),("Accept:application/json")}) + @DELETE("discount/{id}") + Call deleteSellerDiscount(@Path("id") int id,@Header("Authorization") String auth); + + //set the devicetoken for fcm notifications + + @Headers({("Content-Type:application/json"),("Accept:application/json")}) + @PUT("user/deviceToken") + Call registerFcmToken(@Body FcmToken deviceToken, @Header("Authorization") String auth); + + //set the location of USer + @Headers({("Content-Type:application/json"),("Accept:application/application/json")}) + @PUT("updateUserLocation") + Call setUserLocation(@Body Location location, @Header("Authorization") String auth); + + @Headers({("Content-Type:application/json"),("Accept:application/json")}) + @POST("refresh") + Call refreshAccessToken(@Field("refresh_token")String refresh_token); } \ No newline at end of file diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/MockUserService.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/MockUserService.java new file mode 100644 index 0000000..30790f4 --- /dev/null +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/MockUserService.java @@ -0,0 +1,179 @@ +package eu.jnksoftware.discountfinderandroid.services; + +import java.util.List; + +import eu.jnksoftware.discountfinderandroid.Apis.PostShop; +import eu.jnksoftware.discountfinderandroid.Apis.UpdatePostShop; +import eu.jnksoftware.discountfinderandroid.models.Category; +import eu.jnksoftware.discountfinderandroid.models.Location; +import eu.jnksoftware.discountfinderandroid.models.SellerDiscount; +import eu.jnksoftware.discountfinderandroid.models.Shop; +import eu.jnksoftware.discountfinderandroid.models.discountPreferences.DiscountPreferencesPostResponse; +import eu.jnksoftware.discountfinderandroid.models.discountPreferences.DiscountPreferencesRequest; +import eu.jnksoftware.discountfinderandroid.models.discountPreferences.DiscountPreferencesResponse; +import eu.jnksoftware.discountfinderandroid.models.discounts.Discount; +import eu.jnksoftware.discountfinderandroid.models.discounts.DiscountGet; +import eu.jnksoftware.discountfinderandroid.models.discounts.DiscountPost; +import eu.jnksoftware.discountfinderandroid.models.discounts.TopDiscount; +import eu.jnksoftware.discountfinderandroid.models.token.FcmToken; +import eu.jnksoftware.discountfinderandroid.models.token.User; +import retrofit2.Call; +import retrofit2.mock.BehaviorDelegate; + +/** + * Created by nikos on 4/1/2018. + */ + +public class MockUserService implements IuserService { + private final BehaviorDelegate delegate; + + public MockUserService(BehaviorDelegate service){ + this.delegate=service; + } + + @Override + public Call login(String username, String password) { + User user=new User(); + user.setAccessToken("access"); + user.setExpiresIn(5100); + user.setRefreshToken("5100"); + user.setTokenType("Bearer"); + return delegate.returningResponse(user).login(username,password); + } + + @Override + public Call register(String firstName, String lastName, String eMail, String password) { + User user=new User(); + user.setTokenType("Bearer"); + user.setRefreshToken("refresh"); + user.setAccessToken("access"); + user.setExpiresIn(5000); + return delegate.returningResponse(user).register(firstName,lastName,eMail,password); + } + + + + @Override + public Call putDiscountPreferences(int id, DiscountPreferencesRequest discountPreferencesRequest, String auth) { + DiscountPreferencesResponse discountPreferencesResponse=new DiscountPreferencesResponse(); + discountPreferencesResponse.setCategory(1); + discountPreferencesResponse.setId(1); + discountPreferencesResponse.setPrice(40); + discountPreferencesResponse.setTags("tag"); + return delegate.returningResponse(discountPreferencesResponse).putDiscountPreferences(id,discountPreferencesRequest,auth); + } + + @Override + public Call postDiscountPreferences(DiscountPreferencesRequest discountPreferencesPostRequest, String auth) { + DiscountPreferencesRequest discountPreferencesRequest=new DiscountPreferencesRequest(); + discountPreferencesRequest.setPrice("40"); + discountPreferencesRequest.setCategory("shoes"); + discountPreferencesRequest.setTags("tag"); + DiscountPreferencesPostResponse discountPreferencesPostResponse=new DiscountPreferencesPostResponse(); + discountPreferencesPostResponse.setCategory("shoes"); + discountPreferencesPostResponse.setPrice("40"); + discountPreferencesPostResponse.setId(1); + discountPreferencesPostResponse.setTags("tag"); + return delegate.returningResponse(discountPreferencesPostResponse).postDiscountPreferences(discountPreferencesRequest,auth); + } + + @Override + public Call getOneDiscountPreference(int id) { + return null; + } + + @Override + public Call> getDiscountsPreference(String auth) { + return null; + } + + @Override + public Call deleteDiscountPreference(int id, String auth) { + return null; + } + + @Override + public Call> fetchCategories() { + return null; + } + + @Override + public Call> getDiscounts(int distance, String auth) { + return null; + } + + @Override + public Call> getTopDiscounts(int distance, String auth) { + return null; + } + + @Override + public Call deleteShop(int id, String auth) { + return null; + } + + @Override + public Call> getShopsList() { + return null; + } + + @Override + public Call> getShopWithId(int id) { + return null; + } + + @Override + public Call> getUserShops() { + return null; + } + + @Override + public Call> getUserShopWithId(int id) { + return null; + } + + @Override + public Call> getUserShops(String auth) { + return null; + } + + @Override + public Call addShop(PostShop postShop, String auth) { + return null; + } + + @Override + public Call updateShop(UpdatePostShop updatePostShop, String auth) { + return null; + } + + @Override + public Call addDiscount(DiscountPost discountPost, String auth) { + return null; + } + + @Override + public Call> getSellerDiscounts(int shopId, String auth) { + return null; + } + + @Override + public Call deleteSellerDiscount(int id, String auth) { + return null; + } + + @Override + public Call registerFcmToken(FcmToken deviceToken, String auth) { + return null; + } + + @Override + public Call setUserLocation(Location location, String auth) { + return null; + } + + @Override + public Call refreshAccessToken(String refresh_token) { + return null; + } +} diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/MyFirebaseInstanceIDService.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/MyFirebaseInstanceIDService.java index bbc8c9c..ef5b1d3 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/MyFirebaseInstanceIDService.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/services/MyFirebaseInstanceIDService.java @@ -1,18 +1,59 @@ package eu.jnksoftware.discountfinderandroid.services; +import android.content.SharedPreferences; import android.util.Log; +import android.widget.Toast; import com.google.firebase.iid.FirebaseInstanceId; import com.google.firebase.iid.FirebaseInstanceIdService; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import org.json.JSONException; +import org.json.JSONObject; + +import eu.jnksoftware.discountfinderandroid.Apis.HttpCall; +import eu.jnksoftware.discountfinderandroid.Utilities.ManageSharePrefs; +import eu.jnksoftware.discountfinderandroid.models.token.FcmToken; +import eu.jnksoftware.discountfinderandroid.models.token.User; +import eu.jnksoftware.discountfinderandroid.ui.general.Login; public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService { - private static final String REG_TOKEN="REG_TOKEN"; + private static final String REG_TOKEN = "REG_TOKEN"; + private FcmToken fcmToken; + private String auth; + private HttpCall httpCall; + private boolean authenticate; + private int statusCode; + private User currentUser; @Override public void onTokenRefresh() { - String recent_token= FirebaseInstanceId.getInstance().getToken(); - Log.d(REG_TOKEN,recent_token); + String recent_token = FirebaseInstanceId.getInstance().getToken(); + Log.d(REG_TOKEN, recent_token); + fcmToken = new FcmToken(recent_token); + + do { + currentUser = ManageSharePrefs.readUser(null); + if (currentUser != null) { + auth=currentUser.getTokenType()+" "+currentUser.getAccessToken(); + httpCall = new HttpCall(); + statusCode = httpCall.setFcmToken(fcmToken, auth); + if (statusCode == 200) { + ManageSharePrefs.writeFcmTokenData(currentUser.getAccessToken()); + } + authenticate=true; + } else { + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } while (authenticate == false); } -} + + +} \ No newline at end of file diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/MenuCustomer.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/MenuCustomer.java index 752b76d..ddb2ba7 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/MenuCustomer.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/MenuCustomer.java @@ -1,148 +1,91 @@ package eu.jnksoftware.discountfinderandroid.ui.customer; -import android.content.Intent; import android.os.Bundle; -import android.os.Handler; -import android.support.v7.app.AppCompatActivity; +import android.provider.MediaStore; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.support.v7.widget.DefaultItemAnimator; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; import android.view.View; -import android.widget.Button; +import android.view.ViewGroup; import android.widget.Toast; -import com.google.gson.Gson; - +import java.util.ArrayList; +import java.util.List; +import eu.jnksoftware.discountfinderandroid.Apis.ApiUtils; import eu.jnksoftware.discountfinderandroid.R; -import eu.jnksoftware.discountfinderandroid.models.token.UserTokenResponse; -import eu.jnksoftware.discountfinderandroid.services.GeoLocation; -import eu.jnksoftware.discountfinderandroid.ui.customer.recyclers.DiscountCustomerRecyclerList; -import eu.jnksoftware.discountfinderandroid.ui.customer.shops.SellerShops; -import eu.jnksoftware.discountfinderandroid.ui.customer.userPreferences.UserPreferenceList; -import eu.jnksoftware.discountfinderandroid.ui.general.AboutUs; -import eu.jnksoftware.discountfinderandroid.ui.general.Settings; - -public class MenuCustomer extends AppCompatActivity { - - private GeoLocation geoLocation; - private UserTokenResponse userTokenResponse; - String auth; - +import eu.jnksoftware.discountfinderandroid.Utilities.ManageSharePrefs; +import eu.jnksoftware.discountfinderandroid.models.discounts.TopDiscount; +import eu.jnksoftware.discountfinderandroid.services.IuserService; +import eu.jnksoftware.discountfinderandroid.ui.customer.adapters.TopDiscountAdapter; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +public class MenuCustomer extends Fragment { + + private IuserService iuserService; + private String auth; + private RecyclerView topDiscountsRecycler; + private TopDiscountAdapter topDiscountAdapter; + private List topDiscounts; + + @Nullable @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_menu_customer); - - Gson user = new Gson(); - userTokenResponse = user.fromJson(getIntent().getStringExtra("User"),UserTokenResponse.class); - Toast.makeText(getApplicationContext(), "Token :"+userTokenResponse.getTokenType(), Toast.LENGTH_LONG).show(); - - geoLocation = new GeoLocation(this); - - if (geoLocation.canGetLocation()) { - - double latitude = geoLocation.getLatitude(); - double longitude = geoLocation.getLongitude(); - Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show(); - } - - Button about = findViewById(R.id.aboutBtn); - about.setOnClickListener(aboutClick); - Button settings = findViewById(R.id.settingsBtn); - settings.setOnClickListener(settingsClick); - - Button myShops = findViewById(R.id.showShopsButton); - myShops.setOnClickListener(showShopsButtonClick); - Button filtersBtn = findViewById(R.id.filtersBtn); - filtersBtn.setOnClickListener(filtersButtonClick); - Button myDiscount = findViewById(R.id.showDiscountsBtn); - myDiscount.setOnClickListener(discountClick); + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + return inflater.inflate(R.layout.activity_menu_customer,container,false); } - private final View.OnClickListener showShopsButtonClick = new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(MenuCustomer.this, SellerShops.class); - Gson user = new Gson(); - intent.putExtra("User", user.toJson(userTokenResponse)); - startActivity(intent); - } - }; + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + auth = getArguments().getString("auth"); + topDiscountsRecycler = view.findViewById(R.id.topDiscountsRecyclerView); + iuserService= ApiUtils.getUserService(); + +// SEE WHATS WITH THIS,FROM MERGE +// myLocation =ManageSharePrefs.readLocation(""); +// if (myLocation==null) { +// Toast.makeText(getApplicationContext(), "No location ", Toast.LENGTH_LONG).show(); +// GeoLocation myGeoloc =new GeoLocation(); +// myLocation.setLogPos(myGeoloc.getLongitude()); +// myLocation.setLatPos(myGeoloc.getLatitude()); +// } +// ManageSharePrefs.writeLocation(myLocation); + setUpRecycler(); + topDiscounts = new ArrayList<>(); + getTopDiscounts(); + } - private final View.OnClickListener discountClick = new View.OnClickListener() { - @Override - public void onClick(final View v) { - if (geoLocation.getLocation() != null) { - try { - Intent intent=new Intent(MenuCustomer.this,DiscountCustomerRecyclerList.class); - auth = userTokenResponse.getAccessToken(); - intent.putExtra("auth", auth); - intent.putExtra("latitude", geoLocation.getLatitude()); - intent.putExtra("longitude", geoLocation.getLongitude()); - startActivity(intent); + public void setUpRecycler(){ + LinearLayoutManager manager = new LinearLayoutManager(getContext()); + manager.setOrientation(LinearLayoutManager.HORIZONTAL); + topDiscountsRecycler.setLayoutManager(manager); + topDiscountsRecycler.setItemAnimator(new DefaultItemAnimator()); +// topDiscountsRecycler.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL)); + topDiscountsRecycler.setHasFixedSize(true); + } - } catch (Exception ex) { - Toast.makeText(MenuCustomer.this, ex.getMessage(), Toast.LENGTH_SHORT).show(); + public void getTopDiscounts(){ + Call> call = iuserService.getTopDiscounts(15000,auth); + call.enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + if(response.body()!=null) { + topDiscounts = response.body(); + TopDiscountAdapter adapter = new TopDiscountAdapter(getContext(), topDiscounts); + topDiscountsRecycler.setAdapter(adapter); } - } else { - Toast.makeText(MenuCustomer.this, "We don't have your location yet !", Toast.LENGTH_SHORT).show(); } - } - }; - - private final View.OnClickListener aboutClick = new View.OnClickListener() { - @Override - public void onClick(final View v) { - startActivity(new Intent(MenuCustomer.this, AboutUs.class)); - } - }; - - private final View.OnClickListener settingsClick = new View.OnClickListener() { - @Override - public void onClick(View view) { - Button button = findViewById(R.id.showShopsButton); - Intent intent = new Intent(MenuCustomer.this, Settings.class); - intent.putExtra("isSellerEnabled", button.isShown()); - startActivity(intent); - } - }; - - private final View.OnClickListener filtersButtonClick = new View.OnClickListener() { - @Override - public void onClick(View view) { - Gson user=new Gson(); - Intent userPreferences=new Intent(MenuCustomer.this,UserPreferenceList.class); - userPreferences.putExtra("User", user.toJson(userTokenResponse)); - startActivity(userPreferences); - } - }; - private final View.OnClickListener shopClick = new View.OnClickListener() { - @Override - public void onClick(final View v) { - startActivity(new Intent(MenuCustomer.this, AboutUs.class)); - } - }; - - boolean doubleBackPressed = false; - @Override - public void onBackPressed() { - - if (doubleBackPressed) { - Intent intent = new Intent(Intent.ACTION_MAIN); - intent.addCategory(Intent.CATEGORY_HOME); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); - startActivity(intent); - finish(); - System.exit(0); - }doubleBackPressed = true; - - Toast.makeText(MenuCustomer.this,"Please press BACK again to exit",Toast.LENGTH_LONG).show(); - new Handler().postDelayed(new Runnable(){ @Override - public void run(){ - doubleBackPressed = false; + public void onFailure(Call> call, Throwable t) { } - }, 3000); - doubleBackPressed = true; + }); } + } \ No newline at end of file diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/adapters/DiscountRecyclerAdapter.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/adapters/DiscountRecyclerAdapter.java index 5f827a1..4293197 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/adapters/DiscountRecyclerAdapter.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/adapters/DiscountRecyclerAdapter.java @@ -9,10 +9,17 @@ import android.widget.ImageView; import android.widget.TextView; +import com.squareup.picasso.Picasso; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; import java.util.List; import eu.jnksoftware.discountfinderandroid.R; + import eu.jnksoftware.discountfinderandroid.models.discounts.Discount; import eu.jnksoftware.discountfinderandroid.ui.customer.discount.FullContentDiscount; @@ -35,15 +42,13 @@ public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { @Override public void onBindViewHolder(MyViewHolder holder, int position) { - + String imageURL = "https://img.grouponcdn.com/deal/8DDtq5XRzVnLXEUnPHPd/p2-2048x1229/v1/c700x420.jpg"; //Discount Card //Discount discount = discountArrayList.get(position); holder.title.setText("Περιγραφή :" + discountArrayList.get(position).getShortDescription()); holder.shop.setText("Κατάστημα :" + discountArrayList.get(position).getShopName()); - holder.price.setText("Τιμή :" + String.valueOf(discountArrayList.get(position).getFinalPrice())+"€"); - //holder.image.setImageBitmap(discountArrayList.get(position).getProductImageUrl()) - - + holder.price.setText("Τιμή :" + String.valueOf(discountArrayList.get(position).getFinalPrice())+" €"); + Picasso.with(context).load(discountArrayList.get(position).getProductImageURL()).noPlaceholder().fit().into(holder.image); } @Override @@ -76,8 +81,8 @@ public void onClick(View v) { int position = getAdapterPosition(); Discount discount = this.discountList.get(position); Intent intent = new Intent(this.context,FullContentDiscount.class); - intent.putExtra("discount_id",String.valueOf(discount.getId())); - intent.putExtra("discount_image",discount.getProductImageUrl()); + intent.putExtra("discount_id",String.valueOf(discount.getDiscountId())); + intent.putExtra("discount_image",discount.getProductImageURL()); intent.putExtra("discount_Category",discount.getCategory()); intent.putExtra("discount_Description",discount.getShortDescription()); intent.putExtra("discount_Distance",String.valueOf(discount.getDistance())); diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/adapters/ShopDiscountAdapter.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/adapters/ShopDiscountAdapter.java index f2a0e00..2173393 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/adapters/ShopDiscountAdapter.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/adapters/ShopDiscountAdapter.java @@ -11,10 +11,13 @@ import android.widget.RelativeLayout; import android.widget.TextView; +import com.squareup.picasso.Picasso; + import java.util.List; import eu.jnksoftware.discountfinderandroid.R; import eu.jnksoftware.discountfinderandroid.models.SellerDiscount; +import eu.jnksoftware.discountfinderandroid.models.discounts.DiscountPost; public class ShopDiscountAdapter extends RecyclerView.Adapter { private Context context; @@ -38,7 +41,7 @@ public ShopDiscountAdapter.DiscountViewHolder onCreateViewHolder(ViewGroup paren @Override public void onBindViewHolder(ShopDiscountAdapter.DiscountViewHolder holder, int position) { holder.title.setText(discounts.get(position).getDescription()); -// holder.image.setImageBitmap(discounts.get(position).getImage()); + Picasso.with(context).load(discounts.get(position).getImage()).into(holder.image); holder.price.setText("Τιμή " + Integer.toString((int) discounts.get(position).getCurrentPrice())); holder.percentage.setText("Έκπτωση " + Integer.toString((int) discounts.get(position).getDiscountPercent()) + "%"); holder.category.setText("Κατηγορία: " + Integer.toString(discounts.get(position).getCategory())); diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/adapters/TopDiscountAdapter.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/adapters/TopDiscountAdapter.java new file mode 100644 index 0000000..e2a86ee --- /dev/null +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/adapters/TopDiscountAdapter.java @@ -0,0 +1,66 @@ +package eu.jnksoftware.discountfinderandroid.ui.customer.adapters; + + +import android.content.Context; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import com.squareup.picasso.Picasso; + +import java.util.List; + +import eu.jnksoftware.discountfinderandroid.R; +import eu.jnksoftware.discountfinderandroid.models.discounts.TopDiscount; + +public class TopDiscountAdapter extends RecyclerView.Adapter{ + private Context context; + private List topDiscountList; + + public TopDiscountAdapter(Context context, List topDiscountList) { + this.context = context; + this.topDiscountList = topDiscountList; + } + + public List getTopDiscountList(){ + return topDiscountList; + } + + @Override + public topDiscountViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.top_discount_element,parent,false); + return new topDiscountViewHolder(view); + } + + @Override + public void onBindViewHolder(topDiscountViewHolder holder, int position) { + holder.shortDesc.setText(topDiscountList.get(position).getShortDescription()); + Picasso.with(context).load(topDiscountList.get(position).getProductImage()).noPlaceholder().fit().into(holder.productImage); + } + + @Override + public int getItemCount() { + return topDiscountList.size(); + } + + + public static class topDiscountViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ + private TextView shortDesc; + private ImageView productImage; + + public topDiscountViewHolder(View itemView) { + super(itemView); + this.shortDesc = itemView.findViewById(R.id.topDiscountTitle); + this.productImage = itemView.findViewById(R.id.topDiscountImage); + } + + @Override + public void onClick(View view) { + + } + } + +} diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/discount/FullContentDiscount.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/discount/FullContentDiscount.java index 802bec9..ca2dc70 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/discount/FullContentDiscount.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/discount/FullContentDiscount.java @@ -1,13 +1,17 @@ package eu.jnksoftware.discountfinderandroid.ui.customer.discount; +import android.content.Context; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.ImageView; import android.widget.TextView; +import com.squareup.picasso.Picasso; + import eu.jnksoftware.discountfinderandroid.R; public class FullContentDiscount extends AppCompatActivity { + Context context; ImageView discountImage; TextView discountId,discountCategory,discountDescription,discountDistance,discountPrice,discountShopName; @@ -23,7 +27,7 @@ protected void onCreate(Bundle savedInstanceState) { discountPrice = findViewById(R.id.discountPrice); discountShopName = findViewById(R.id.discountShopName); - discountImage.setImageResource(getIntent().getIntExtra("discount_image",0)); + Picasso.with(context).load(getIntent().getStringExtra("discount_image")).noPlaceholder().fit().into(discountImage); discountId.setText("Discount Id : " + getIntent().getStringExtra("discount_id")); discountCategory.setText("Category : " + getIntent().getStringExtra("discount_Category")); discountDescription.setText("Description : " + getIntent().getStringExtra("discount_Description")); diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/recyclers/DiscountCustomerRecyclerList.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/recyclers/DiscountCustomerRecyclerList.java index 035a399..6ce0eb1 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/recyclers/DiscountCustomerRecyclerList.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/recyclers/DiscountCustomerRecyclerList.java @@ -1,102 +1,88 @@ package eu.jnksoftware.discountfinderandroid.ui.customer.recyclers; - import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; import android.widget.SeekBar; import android.widget.TextView; import android.widget.Toast; - import java.util.ArrayList; import java.util.List; - -import eu.jnksoftware.discountfinderandroid.Apis.DiscountsApiInterface; -import eu.jnksoftware.discountfinderandroid.Apis.PostDiscount; -import eu.jnksoftware.discountfinderandroid.Apis.RestClient; +import eu.jnksoftware.discountfinderandroid.Apis.ApiUtils; import eu.jnksoftware.discountfinderandroid.R; +import eu.jnksoftware.discountfinderandroid.Utilities.ManageSharePrefs; import eu.jnksoftware.discountfinderandroid.models.Location; import eu.jnksoftware.discountfinderandroid.models.discounts.Discount; +import eu.jnksoftware.discountfinderandroid.models.token.User; +import eu.jnksoftware.discountfinderandroid.services.GeoLocation; +import eu.jnksoftware.discountfinderandroid.services.IuserService; import eu.jnksoftware.discountfinderandroid.ui.customer.adapters.DiscountRecyclerAdapter; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; -public class DiscountCustomerRecyclerList extends AppCompatActivity { - private int barProgress = 0; +public class DiscountCustomerRecyclerList extends Fragment { + private int barProgress = 15000; private SeekBar distanceBar; private TextView distanceText; private RecyclerView recyclerView; private RecyclerView.Adapter adapter; private RecyclerView.LayoutManager layoutManager; private List discountProducts = new ArrayList<>(); - private DiscountsApiInterface supportApi; - private String auth; - private double latitude ,longitude; - private Location location = new Location(); - - protected void onCreate(Bundle savedInstanceState) { + private IuserService supportApi; + private User user; + String auth; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState){ + return inflater.inflate(R.layout.activity_discount_customer_recycler_list,container,false); + } - super.onCreate(savedInstanceState); + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); - distanceBar = findViewById(R.id.distanceSeekBar); - distanceText = findViewById(R.id.distanceTextView); + distanceBar = getView().findViewById(R.id.distanceSeekBar); + distanceText = getView().findViewById(R.id.distanceTextView); + recyclerView = getView().findViewById(R.id.recyclerView); - setContentView(R.layout.activity_discount_customer_recycler_list); - recyclerView = findViewById(R.id.recyclerView); - layoutManager = new LinearLayoutManager(this); + layoutManager = new LinearLayoutManager(getContext()); recyclerView.setLayoutManager(layoutManager); recyclerView.setHasFixedSize(true); - auth = "Bearer " + getIntent().getStringExtra("auth"); - latitude = getIntent().getDoubleExtra("latitude", location.getLatitude()); - longitude = getIntent().getDoubleExtra("longitude",location.getLongitude()); - - supportApi = RestClient.getClient().create(DiscountsApiInterface.class); + auth = getArguments().getString("auth"); + supportApi = ApiUtils.getUserService(); seekBarProgressCalc(); fillDiscountProductsList(); } - private void fillDiscountProductsList() { - /*Category category = new Category("1", "1"); - discountProducts.add(new Discount(1, category, "Pc", "Tech", 100, "https://www.cyberpowerpc.com/images/cs/smraidmax/blk_400.png", 500)); - adapter = new DiscountRecyclerAdapter(discountProducts); - recyclerView.setAdapter(adapter);*/ - - - //Location for discounts : logPos = 41.088535 , latPos = 23.551294 & distanceInMeters = barProgress - longitude = 41.088535; - latitude = 23.551294; - final PostDiscount postDiscount = new PostDiscount(longitude, latitude, 1500); - Toast.makeText(DiscountCustomerRecyclerList.this, "Longitude :" + String.valueOf(longitude) + "\n Latitude :" + String.valueOf(latitude), Toast.LENGTH_SHORT).show(); - Call> call = supportApi.getDiscounts(postDiscount, auth); + private void fillDiscountProductsList() { + Call> call = supportApi.getDiscounts(15000, auth); call.enqueue(new Callback>() { @Override public void onResponse(Call> call, Response> response) { discountProducts = response.body(); - //discountProducts.add(new Discount(1,"deli","eleos","me",10,"ta API",1)); - adapter = new DiscountRecyclerAdapter(discountProducts , getBaseContext()); + adapter = new DiscountRecyclerAdapter(discountProducts , getContext()); recyclerView.setAdapter(adapter); } @Override public void onFailure(Call> call, Throwable t) { - Toast.makeText(DiscountCustomerRecyclerList.this, "Error", Toast.LENGTH_SHORT).show(); + Toast.makeText(getContext(), "Error", Toast.LENGTH_SHORT).show(); t.getLocalizedMessage(); } }); } - - public void seekBarProgressCalc() { - distanceBar = findViewById(R.id.distanceSeekBar); - distanceText = findViewById(R.id.distanceTextView); - distanceText.setText(barProgress + " m"); //TODO : make it start from 500 not from 0 @@ -120,7 +106,24 @@ public void onStartTrackingTouch(SeekBar seekBar) { @Override public void onStopTrackingTouch(SeekBar seekBar) { distanceText.setText(barProgress + " m"); + Call> call = supportApi.getDiscounts(barProgress, auth); + call.enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + discountProducts = response.body(); + adapter = new DiscountRecyclerAdapter(discountProducts , getContext()); + recyclerView.setAdapter(adapter); + + } + + @Override + public void onFailure(Call> call, Throwable t) { + Toast.makeText(getContext(), "Error", Toast.LENGTH_SHORT).show(); + t.getLocalizedMessage(); + } + }); } }); } + } diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/recyclers/RecyclerPreference.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/recyclers/RecyclerPreference.java index 2c645ed..fa78778 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/recyclers/RecyclerPreference.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/recyclers/RecyclerPreference.java @@ -6,6 +6,8 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; @@ -34,20 +36,24 @@ public RecyclerPreference(List discountPreferencesR this.auth=auth; } + public List getDiscountPreferencesResponses() { + return discountPreferencesResponses; + } + @Override public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.row_item_preference_list,parent,false); - return new MyViewHolder(view); + return new MyViewHolder(view,mContext); } @Override public void onBindViewHolder(final MyViewHolder holder, int position) { holder.tags.setText(discountPreferencesResponses.get(position).getTags()); - holder.price.setText(Integer.toString(discountPreferencesResponses.get(position).getPrice())); + holder.price.setText(Float.toString(discountPreferencesResponses.get(position).getPrice())); holder.categoryTitle.setText(discountPreferencesResponses.get(position).getCategoryTitle()); holder.id.setText(Integer.toString(discountPreferencesResponses.get(position).getId())); - holder.delete.setOnClickListener(new View.OnClickListener() { + /* holder.delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int idpref; @@ -55,50 +61,63 @@ public void onClick(View view) { deletePref(idpref,auth); discountPreferencesResponses.remove(holder.getAdapterPosition()); notifyDataSetChanged(); + } - }); + }); */ + + } + public void removeDiscount(int position){ + discountPreferencesResponses.remove(position); } + public void restoreDiscount(DiscountPreferencesResponse discount,int position){ + discountPreferencesResponses.add(position,discount); + } + public int getDiscountId(int position){ + return discountPreferencesResponses.get(position).getId(); + } + + + @Override public int getItemCount() { return discountPreferencesResponses.size(); } - public static class MyViewHolder extends RecyclerView.ViewHolder { - Button delete; + public static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { + // Button delete; TextView id; TextView price; + Context context; + LinearLayout foregroundViewPreference; + RelativeLayout backgroundViewPreference; TextView tags; TextView categoryTitle; - public MyViewHolder(View itemView) { + public MyViewHolder(View itemView,Context context) { super(itemView); - delete=itemView.findViewById(R.id.openStoreButton); + //delete=itemView.findViewById(R.id.openStoreButton); id=itemView.findViewById(R.id.idPref); price=itemView.findViewById(R.id.priceText); tags=itemView.findViewById(R.id.tagsTextView); + this.context = context; categoryTitle=itemView.findViewById(R.id.categoryTextView); + foregroundViewPreference = itemView.findViewById(R.id.foreground_view_userpref); + backgroundViewPreference = itemView.findViewById(R.id.background_view_userpref); + + itemView.setOnClickListener(this); } + @Override + public void onClick(View view) { + + } } - public void deletePref(final int id, String auth) - { iuserService= ApiUtils.getUserService(); - Call delete=iuserService.deleteDiscountPreference(id,auth); - delete.enqueue(new Callback() { - @Override - public void onResponse(Call call, Response response) { - Toast.makeText(mContext,"You Preference with "+id+" remove Succesfully",Toast.LENGTH_SHORT).show(); - } - @Override - public void onFailure(Call call, Throwable t) { - } - }); - } } diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/SellerAddDiscount.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/SellerAddDiscount.java index 4988a10..7f2cbff 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/SellerAddDiscount.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/SellerAddDiscount.java @@ -1,57 +1,122 @@ package eu.jnksoftware.discountfinderandroid.ui.customer.shops; +import android.content.Intent; +import android.graphics.Bitmap; +import android.net.Uri; import android.os.Bundle; +import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; +import android.util.Base64; import android.view.View; import android.widget.Button; import android.widget.EditText; +import android.widget.ImageView; import android.widget.Toast; -import eu.jnksoftware.discountfinderandroid.Apis.RestClient; -import eu.jnksoftware.discountfinderandroid.Apis.ShopsApiInterface; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import eu.jnksoftware.discountfinderandroid.Apis.ApiUtils; import eu.jnksoftware.discountfinderandroid.R; +import eu.jnksoftware.discountfinderandroid.Utilities.ManageSharePrefs; import eu.jnksoftware.discountfinderandroid.models.discounts.DiscountGet; import eu.jnksoftware.discountfinderandroid.models.discounts.DiscountPost; +import eu.jnksoftware.discountfinderandroid.models.token.User; +import eu.jnksoftware.discountfinderandroid.services.IuserService; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; public class SellerAddDiscount extends AppCompatActivity { - ShopsApiInterface apiInterface; - String auth; - double startingPrice; - double finalPrice; - String description; - int categoryId; - String image; + private IuserService apiInterface; + private String auth; + private User user; + private int shopId; + private double startPrice; + private double endPrice; + private String desc; + private int categoryId; + private String image; + private Button myDiscount; + private Long tsLong; + private Button choosePhoto; + private Bitmap discountPhoto; + private ImageView discountImageView; + private EditText startingPrice; + private EditText finalPrice; + private EditText description; + private int PICK_IMAGE_REQUEST = 1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_seller_add_discount); - Button myDiscount = findViewById(R.id.addMyDiscountButton); - myDiscount.setOnClickListener(myDiscountClick); + apiInterface = ApiUtils.getUserService(); + user = ManageSharePrefs.readUser(null); + - apiInterface = RestClient.getClient().create(ShopsApiInterface.class); - auth = getIntent().getStringExtra("auth"); + shopId = getIntent().getIntExtra("shopId",-1); + tsLong = System.currentTimeMillis()/1000; + myDiscount = findViewById(R.id.addMyDiscountButton); + myDiscount.setOnClickListener(myDiscountClick); + choosePhoto = findViewById(R.id.choosePhotoButton); + choosePhoto.setOnClickListener(choosePhotoClick); + startingPrice = findViewById(R.id.etStartingPrice); + finalPrice = findViewById(R.id.etFinalPrice); + description = findViewById(R.id.etDescription); + discountImageView = findViewById(R.id.newDiscountImage); } private View.OnClickListener myDiscountClick = new View.OnClickListener() { @Override public void onClick(View view) { - getDiscountValues(); - addDiscount(); + + DiscountPost discountPost=new DiscountPost(); + image=imageToString(); + + discountPost.setImageBase(image); + discountPost.setImageTitle(tsLong.toString()); + discountPost.setShopId(shopId); + discountPost.setCurrentPrice(Double.parseDouble(finalPrice.getText().toString().trim())); + discountPost.setOriginalPrice(Double.parseDouble(startingPrice.getText().toString().trim())); + discountPost.setDescription(description.getText().toString()); + discountPost.setCategory(2); + addDiscount(discountPost); + } + }; + + private View.OnClickListener choosePhotoClick = new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent showGallery = new Intent(); + showGallery.setType("image/*"); + showGallery.setAction(Intent.ACTION_GET_CONTENT); + startActivityForResult(Intent.createChooser(showGallery,"Select discount picture"),PICK_IMAGE_REQUEST); } }; - public void addDiscount(){ - DiscountPost discountPost = new DiscountPost(categoryId,startingPrice,finalPrice,description,image); + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if(requestCode==PICK_IMAGE_REQUEST && resultCode==RESULT_OK && data!=null && data.getData()!=null){ + Uri path=data.getData(); + try { + discountPhoto= MediaStore.Images.Media.getBitmap(getContentResolver(),path); + discountImageView.setImageBitmap(discountPhoto); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + public void addDiscount(DiscountPost discountPost){ + auth="Bearer "+user.getAccessToken(); Call call = apiInterface.addDiscount(discountPost,auth); call.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { - Toast.makeText(SellerAddDiscount.this, response.message() + "\nDiscount Added", Toast.LENGTH_SHORT).show(); + if(response.message().equals("OK")) finish(); } @@ -62,15 +127,12 @@ public void onFailure(Call call, Throwable t) { }); } - public void getDiscountValues(){ - EditText startingPrice = findViewById(R.id.etStartingPrice); - EditText finalPrice = findViewById(R.id.etFinalPrice); - EditText description = findViewById(R.id.etDescription); - - this.startingPrice = Double.parseDouble(startingPrice.getText().toString()); - this.finalPrice = Double.parseDouble(finalPrice.getText().toString()); - this.description = description.getText().toString(); - this.categoryId = 1; - this.image = "img.google.gr"; + public String imageToString() { + ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream(); + discountPhoto.compress(Bitmap.CompressFormat.JPEG,50,byteArrayOutputStream); + byte[] imgByte=byteArrayOutputStream.toByteArray(); + return Base64.encodeToString(imgByte, Base64.DEFAULT); } + + } diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/SellerAddShop.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/SellerAddShop.java index 35f74fb..8894f08 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/SellerAddShop.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/SellerAddShop.java @@ -6,19 +6,27 @@ import android.view.View; import android.widget.Button; import android.widget.EditText; +import android.widget.TextView; import android.widget.Toast; +import eu.jnksoftware.discountfinderandroid.Apis.ApiUtils; import eu.jnksoftware.discountfinderandroid.Apis.PostShop; -import eu.jnksoftware.discountfinderandroid.Apis.RestClient; -import eu.jnksoftware.discountfinderandroid.Apis.ShopsApiInterface; +import eu.jnksoftware.discountfinderandroid.Apis.RetrofitClient; import eu.jnksoftware.discountfinderandroid.R; +import eu.jnksoftware.discountfinderandroid.models.Location; +import eu.jnksoftware.discountfinderandroid.services.ChooseStoreLocation; +import eu.jnksoftware.discountfinderandroid.services.IuserService; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; public class SellerAddShop extends AppCompatActivity { - ShopsApiInterface apiService; + private IuserService apiService; String auth; + Location userLocation = new Location(); + Location storeLocation = new Location(); + private static final int requestCode = 1; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -30,21 +38,49 @@ protected void onCreate(Bundle savedInstanceState) { Button cancelButton = findViewById(R.id.cancelButton); cancelButton.setOnClickListener(cancelButtonClick); - apiService = RestClient.getClient().create(ShopsApiInterface.class); + Button mapsButton = findViewById(R.id.mapsButton); + mapsButton.setOnClickListener(mapsClick); + + ApiUtils apiUtils = new ApiUtils(); + apiService = RetrofitClient.getClient(apiUtils.getBaseUrl()).create(IuserService.class); + apiService = ApiUtils.getUserService(); auth = getIntent().getStringExtra("auth"); + + double userLat = getIntent().getDoubleExtra("lat",-1); + double userLon = getIntent().getDoubleExtra("lon",-1); + userLocation.setLatPos(userLat); + userLocation.setLogPos(userLon); + + } + + private final View.OnClickListener mapsClick = new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(SellerAddShop.this, ChooseStoreLocation.class); + intent.putExtra("lat",userLocation.getLatPos()); + intent.putExtra("lon",userLocation.getLogPos()); + intent.putExtra("auth",auth); + startActivityForResult(intent,requestCode); + } + }; + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if(requestCode == 1 & resultCode == RESULT_OK) { + storeLocation.setLatPos(data.getDoubleExtra("storeLat", -1)); + storeLocation.setLogPos(data.getDoubleExtra("storeLon", -1)); + TextView location = findViewById(R.id.shopMapsLocationTextView); + location.setText(data.getStringExtra("streetName")); + } } private void addShop(){ - String[] pos; EditText shopNameEditText = findViewById(R.id.shopNameEditText); - EditText locationEditText = findViewById(R.id.shopLocationEditText); EditText descriptionEditText = findViewById(R.id.shopDescriptionEditText); - pos = locationEditText.getText().toString().split(" "); String shopName = shopNameEditText.getText().toString(); - double lon = Double.parseDouble(pos[0]); - double lat =Double.parseDouble(pos[1]); - PostShop postShop = new PostShop(shopName,lon,lat); + PostShop postShop = new PostShop(shopName,storeLocation.getLatPos(),storeLocation.getLogPos()); Call call = apiService.addShop(postShop,auth); call.enqueue(new Callback() { @Override @@ -59,17 +95,24 @@ public void onFailure(Call call, Throwable t) { }); } + @Override + public void onBackPressed() { + super.onBackPressed(); + finish(); + } + private final View.OnClickListener insertButtonClick = new View.OnClickListener() { @Override public void onClick(View v) { addShop(); + finish(); } }; private final View.OnClickListener cancelButtonClick = new View.OnClickListener() { @Override public void onClick(View v) { - SellerAddShop.this.startActivity(new Intent(SellerAddShop.this, SellerShops.class)); + finish(); } }; diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/SellerShops.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/SellerShops.java index 658dd9d..3ad1eef 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/SellerShops.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/SellerShops.java @@ -1,56 +1,68 @@ package eu.jnksoftware.discountfinderandroid.ui.customer.shops; + import android.content.Intent; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.Button; import android.widget.Toast; -import com.google.gson.Gson; - import java.util.ArrayList; import java.util.List; -import eu.jnksoftware.discountfinderandroid.Apis.RestClient; -import eu.jnksoftware.discountfinderandroid.Apis.ShopsApiInterface; +import eu.jnksoftware.discountfinderandroid.Apis.ApiUtils; import eu.jnksoftware.discountfinderandroid.R; +import eu.jnksoftware.discountfinderandroid.Utilities.ManageSharePrefs; import eu.jnksoftware.discountfinderandroid.models.Shop; -import eu.jnksoftware.discountfinderandroid.models.token.UserTokenResponse; +import eu.jnksoftware.discountfinderandroid.models.token.User; +import eu.jnksoftware.discountfinderandroid.services.IuserService; import eu.jnksoftware.discountfinderandroid.ui.customer.adapters.RecyclerAdapter; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; -public class SellerShops extends AppCompatActivity { +public class SellerShops extends Fragment { RecyclerView shopsRecyclerView; RecyclerView.Adapter adapter; RecyclerView.LayoutManager layoutManager; List shops = new ArrayList<>(); - ShopsApiInterface apiService; + private IuserService apiService; String auth; + User user; + private static final int requestCode = 1; + + @Nullable @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_seller_shops); - shopsRecyclerView = findViewById(R.id.shopsRecyclerView); - layoutManager = new LinearLayoutManager(this); + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + return inflater.inflate(R.layout.activity_seller_shops,container,false); + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + shopsRecyclerView = view.findViewById(R.id.shopsRecyclerView); + layoutManager = new LinearLayoutManager(getContext()); shopsRecyclerView.setLayoutManager(layoutManager); shopsRecyclerView.setHasFixedSize(true); - Gson user = new Gson(); - UserTokenResponse userTokenResponse = user.fromJson(getIntent().getStringExtra("User"),UserTokenResponse.class); - auth = "Bearer " + userTokenResponse.getAccessToken(); - apiService = RestClient.getClient().create(ShopsApiInterface.class); + user = ManageSharePrefs.readUser(null); + auth= getArguments().getString("auth"); + apiService = ApiUtils.getUserService(); getUserShops(); - Button addStore = findViewById(R.id.addStoreButton); + Button addStore = view.findViewById(R.id.addStoreButton); addStore.setOnClickListener(addStoreButtonClick); - Button refreshButton = findViewById(R.id.refreshButton); + Button refreshButton = view.findViewById(R.id.refreshButton); refreshButton.setOnClickListener(refreshButtonClick); -} + } + private final View.OnClickListener refreshButtonClick = new View.OnClickListener() { @Override @@ -60,19 +72,19 @@ public void onClick(View view) { }; private void getUserShops(){ - Call> call = apiService.getUserShops(auth); + Call> call = apiService.getShopsList(); call.enqueue(new Callback>() { @Override public void onResponse(Call> call, Response> response) { shops = response.body(); - adapter = new RecyclerAdapter(shops,SellerShops.this,auth); + adapter = new RecyclerAdapter(shops,getContext(),user.getAccessToken()); shopsRecyclerView.setAdapter(adapter); } @Override public void onFailure(Call> call, Throwable t) { - Toast.makeText(SellerShops.this, "error occured", Toast.LENGTH_SHORT).show(); + Toast.makeText(getContext(), "error occured", Toast.LENGTH_SHORT).show(); } }); } @@ -80,10 +92,17 @@ public void onFailure(Call> call, Throwable t) { private final View.OnClickListener addStoreButtonClick = new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(SellerShops.this,SellerAddShop.class); + Intent intent = new Intent(getContext(),SellerAddShop.class); intent.putExtra("auth",auth); - startActivity(intent); +// intent.putExtra("lat",userLocation.getLatPos()); +// intent.putExtra("lon",userLocation.getLogPos()); + startActivityForResult(intent,requestCode); } }; + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + getUserShops(); + } } diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/UpdateShop.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/UpdateShop.java index da0e5b5..4416cb7 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/UpdateShop.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/UpdateShop.java @@ -8,17 +8,17 @@ import android.widget.EditText; import android.widget.Toast; -import eu.jnksoftware.discountfinderandroid.Apis.RestClient; -import eu.jnksoftware.discountfinderandroid.Apis.ShopsApiInterface; +import eu.jnksoftware.discountfinderandroid.Apis.ApiUtils; import eu.jnksoftware.discountfinderandroid.Apis.UpdatePostShop; import eu.jnksoftware.discountfinderandroid.R; +import eu.jnksoftware.discountfinderandroid.services.IuserService; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; public class UpdateShop extends AppCompatActivity { - ShopsApiInterface apiService; + private IuserService apiService; String auth; @Override @@ -26,7 +26,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_update_shop); - apiService = RestClient.getClient().create(ShopsApiInterface.class); + apiService = ApiUtils.getUserService(); auth = getIntent().getStringExtra("auth"); Button update = findViewById(R.id.updateButton); diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/ViewStore.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/ViewStore.java index 6ab3e1c..e291168 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/ViewStore.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/shops/ViewStore.java @@ -19,10 +19,12 @@ import java.util.ArrayList; import java.util.List; -import eu.jnksoftware.discountfinderandroid.Apis.RestClient; -import eu.jnksoftware.discountfinderandroid.Apis.ShopsApiInterface; +import eu.jnksoftware.discountfinderandroid.Apis.ApiUtils; import eu.jnksoftware.discountfinderandroid.R; +import eu.jnksoftware.discountfinderandroid.Utilities.ManageSharePrefs; import eu.jnksoftware.discountfinderandroid.models.SellerDiscount; +import eu.jnksoftware.discountfinderandroid.models.token.User; +import eu.jnksoftware.discountfinderandroid.services.IuserService; import eu.jnksoftware.discountfinderandroid.ui.customer.adapters.RecyclerItemTouchHelper; import eu.jnksoftware.discountfinderandroid.ui.customer.adapters.ShopDiscountAdapter; import retrofit2.Call; @@ -35,8 +37,9 @@ public class ViewStore extends AppCompatActivity implements RecyclerItemTouchHel private ShopDiscountAdapter myDiscountsAdapter; private String shopName; private int shopId; - ShopsApiInterface apiService; + private IuserService apiService; private String auth; + private User user; private List discounts = new ArrayList<>(); private ConstraintLayout layout; @@ -60,8 +63,10 @@ protected void onCreate(Bundle savedInstanceState) { setUpRecycler(); - apiService = RestClient.getClient().create(ShopsApiInterface.class); - auth = getIntent().getStringExtra("auth"); + apiService = ApiUtils.getUserService(); + user = ManageSharePrefs.readUser(null); + + shopName = getIntent().getStringExtra("shop"); shopId = getIntent().getIntExtra("shopId",-1); textView.setText(shopName); @@ -102,12 +107,14 @@ public void onClick(View view) { public void onClick(View view) { Intent intent = new Intent(ViewStore.this,SellerAddDiscount.class); intent.putExtra("auth",auth); + intent.putExtra("shopId",shopId); startActivity(intent); } }; private void deleteShop() { - Call call = apiService.deleteShop(shopId, auth); + auth="Bearer "+user.getAccessToken(); + Call call = apiService.deleteShop(shopId,auth); call.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { @@ -122,22 +129,25 @@ public void onFailure(Call call, Throwable t) { } public void getSellerDiscounts(){ - Call> call = apiService.getSellerDiscounts(auth); - call.enqueue(new Callback>() { - @Override - public void onResponse(Call> call, Response> response) { - discounts = response.body(); - Toast.makeText(ViewStore.this,response.message() + "\nLoaded",Toast.LENGTH_SHORT).show(); - myDiscountsAdapter = new ShopDiscountAdapter(ViewStore.this,discounts); - myDiscountsRecycler.setAdapter(myDiscountsAdapter); - } + auth="Bearer "+user.getAccessToken(); + if(this.shopId!=-1) { + Call> call = apiService.getSellerDiscounts(shopId,auth); + call.enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + discounts = response.body(); + Toast.makeText(ViewStore.this, response.message() + "\nLoaded", Toast.LENGTH_SHORT).show(); + myDiscountsAdapter = new ShopDiscountAdapter(ViewStore.this, discounts); + myDiscountsRecycler.setAdapter(myDiscountsAdapter); + } - @Override - public void onFailure(Call> call, Throwable t) { - Toast.makeText(ViewStore.this, "Failed to load the discounts", Toast.LENGTH_SHORT).show(); - call.cancel(); - } - }); + @Override + public void onFailure(Call> call, Throwable t) { + Toast.makeText(ViewStore.this, "Failed to load the discounts", Toast.LENGTH_SHORT).show(); + call.cancel(); + } + }); + } } @Override @@ -173,6 +183,7 @@ public void onClick(View view) { } public void deleteSellerDiscount(int id){ + auth="Bearer "+user.getAccessToken(); Call call = apiService.deleteSellerDiscount(id,auth); call.enqueue(new Callback() { @Override diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/userPreferences/DeletePreference.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/userPreferences/DeletePreference.java index a2d98a2..72f2774 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/userPreferences/DeletePreference.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/userPreferences/DeletePreference.java @@ -12,7 +12,7 @@ import eu.jnksoftware.discountfinderandroid.Apis.ApiUtils; import eu.jnksoftware.discountfinderandroid.R; -import eu.jnksoftware.discountfinderandroid.models.token.UserTokenResponse; +import eu.jnksoftware.discountfinderandroid.models.token.User; import eu.jnksoftware.discountfinderandroid.services.IuserService; import retrofit2.Call; import retrofit2.Callback; @@ -20,14 +20,14 @@ public class DeletePreference extends AppCompatActivity { - UserTokenResponse userTokenResponse; + User user; IuserService iuserService; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_delete_preference); final Gson user = new Gson(); - userTokenResponse = user.fromJson(getIntent().getStringExtra("User"), UserTokenResponse.class); + this.user = user.fromJson(getIntent().getStringExtra("User"), User.class); final EditText id=findViewById(R.id.idTxt); iuserService= ApiUtils.getUserService(); @@ -38,7 +38,7 @@ protected void onCreate(Bundle savedInstanceState) { public void onClick(View view) { String auth; - auth="Bearer "+userTokenResponse.getAccessToken(); + auth="Bearer "+ DeletePreference.this.user.getAccessToken(); int idpref; String s1; s1=id.getText().toString(); diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/userPreferences/UserPreferenceList.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/userPreferences/UserPreferenceList.java index 808851a..45e5ee7 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/userPreferences/UserPreferenceList.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/userPreferences/UserPreferenceList.java @@ -1,12 +1,21 @@ package eu.jnksoftware.discountfinderandroid.ui.customer.userPreferences; import android.content.Intent; +import android.graphics.Color; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import android.support.constraint.ConstraintLayout; +import android.support.design.widget.Snackbar; +import android.support.v4.app.Fragment; +import android.support.v7.widget.DefaultItemAnimator; +import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.helper.ItemTouchHelper; +import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.Button; +import android.widget.Toast; import com.google.gson.Gson; @@ -14,86 +23,91 @@ import eu.jnksoftware.discountfinderandroid.Apis.ApiUtils; import eu.jnksoftware.discountfinderandroid.R; +import eu.jnksoftware.discountfinderandroid.Utilities.ManageSharePrefs; import eu.jnksoftware.discountfinderandroid.models.discountPreferences.DiscountPreferencesResponse; -import eu.jnksoftware.discountfinderandroid.models.token.UserTokenResponse; +import eu.jnksoftware.discountfinderandroid.models.token.User; import eu.jnksoftware.discountfinderandroid.services.IuserService; +import eu.jnksoftware.discountfinderandroid.ui.customer.adapters.RecyclerItemTouchHelper; import eu.jnksoftware.discountfinderandroid.ui.customer.recyclers.RecyclerPreference; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; -public class UserPreferenceList extends AppCompatActivity { - private UserTokenResponse userTokenResponse; - private RecyclerView recyclerView; - private RecyclerView.LayoutManager layoutManager; +public class UserPreferenceList extends Fragment implements RecyclerItemTouchHelper.RecyclerItemTouchHelperListener{ + private User user; + private RecyclerView recyclerView; + private RecyclerView.LayoutManager layoutManager; private RecyclerPreference adapter; - IuserService iuserService; - List discountPreferencesResponses ; + private IuserService iuserService; + private List discountPreferencesResponses ; + private String auth; + private Button addPreference; + private ConstraintLayout layout; @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_user_preference_list); - recyclerView= findViewById(R.id.userPreferenceRecycler); - layoutManager=new LinearLayoutManager(this); + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.activity_user_preference_list,container,false); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + //layout=view.findViewById(R.id.userpreferencesConst); + user = ManageSharePrefs.readUser(null); + iuserService= ApiUtils.getUserService(); + recyclerView= view.findViewById(R.id.userPreferenceRecycler); + layoutManager=new LinearLayoutManager(getContext()); recyclerView.setLayoutManager(layoutManager); + recyclerView.setItemAnimator(new DefaultItemAnimator()); + recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL)); recyclerView.setHasFixedSize(true); - Gson user = new Gson(); - userTokenResponse = user.fromJson(getIntent().getStringExtra("User"), UserTokenResponse.class); - Button deletePreference=findViewById(R.id.deleteprefBtn); - iuserService = ApiUtils.getUserService(); - String auth="Bearer "+userTokenResponse.getAccessToken(); - fetchUserPreferences(auth); - - deletePreference.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Gson user = new Gson(); - - Intent intent=new Intent(UserPreferenceList.this,DeletePreference.class); - intent.putExtra("User", user.toJson(userTokenResponse)); - startActivity(intent); - } - }); - + addPreference = view.findViewById(R.id.userPreferencesBtn); + addPreference.setOnClickListener(addPreferenceClick); + fetchUserPreferences("Bearer "+user.getAccessToken()); + ItemTouchHelper.SimpleCallback itemTouchHelper= new RecyclerItemTouchHelper(0,ItemTouchHelper.LEFT,this); + new ItemTouchHelper(itemTouchHelper).attachToRecyclerView(recyclerView); + } - Button addPrefence = findViewById(R.id.userPreferencesBtn); - addPrefence.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Gson user = new Gson(); - Intent userPreferences = new Intent(UserPreferenceList.this, UserPreferences.class); - userPreferences.putExtra("User", user.toJson(userTokenResponse)); - startActivity(userPreferences); - } - }); - + @Override + public void onResume() { + super.onResume(); + fetchUserPreferences("Bearer "+user.getAccessToken()); + } + /* Button updatePreference=findViewById(R.id.updateprefBtn); updatePreference.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Gson user = new Gson(); Intent userUpdatePreferences = new Intent(UserPreferenceList.this, UserUpdatePreferences.class); - userUpdatePreferences.putExtra("User", user.toJson(userTokenResponse)); + userUpdatePreferences.putExtra("User", user.toJson(UserPreferenceList.this.user)); startActivity(userUpdatePreferences); } }); - } + */ + + private View.OnClickListener addPreferenceClick = new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent userPreferences = new Intent(getActivity(), UserPreferences.class); + getActivity().startActivity(userPreferences); + } + }; public void fetchUserPreferences(final String auth) { + Call> disc=iuserService.getDiscountsPreference(auth); disc.enqueue(new Callback>() { @Override public void onResponse(Call> call, Response> response) { + discountPreferencesResponses=response.body(); - adapter=new RecyclerPreference(discountPreferencesResponses, UserPreferenceList.this,auth); + adapter=new RecyclerPreference(discountPreferencesResponses, getContext(),auth); recyclerView.setAdapter(adapter); - - } @Override @@ -101,11 +115,52 @@ public void onFailure(Call> call, Throwable t) } }); + } + + @Override + public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction, int position) { + if (viewHolder instanceof RecyclerPreference.MyViewHolder){ + String catTitle = discountPreferencesResponses.get(viewHolder.getAdapterPosition()).getCategoryTitle(); + final DiscountPreferencesResponse deletedDiscount=discountPreferencesResponses.get(viewHolder.getAdapterPosition()); + final int deletedIndex = viewHolder.getAdapterPosition(); + + int pos = viewHolder.getAdapterPosition(); + deletePref(adapter.getDiscountId(pos)); + adapter.removeDiscount(pos); + adapter.notifyItemRemoved(pos); + + adapter.notifyDataSetChanged(); + Snackbar snackbar = Snackbar + .make(layout, catTitle + " removed from your shop!", Snackbar.LENGTH_LONG); + snackbar.setAction("UNDO", new View.OnClickListener() { + @Override + public void onClick(View view) { + // undo is selected, restore the deleted item + adapter.restoreDiscount(deletedDiscount, deletedIndex); + adapter.notifyItemInserted(deletedIndex); + } + }); + snackbar.setActionTextColor(Color.YELLOW); + snackbar.show(); + } } + public void deletePref( int id) + { auth="Bearer "+user.getAccessToken(); + iuserService= ApiUtils.getUserService(); + Call delete=iuserService.deleteDiscountPreference(id,auth); + delete.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { - } + } + @Override + public void onFailure(Call call, Throwable t) { + } + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/userPreferences/UserPreferences.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/userPreferences/UserPreferences.java index 2628904..b558ba8 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/userPreferences/UserPreferences.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/userPreferences/UserPreferences.java @@ -1,6 +1,7 @@ package eu.jnksoftware.discountfinderandroid.ui.customer.userPreferences; import android.annotation.SuppressLint; + import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; @@ -8,6 +9,7 @@ import android.view.View; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.EditText; import android.widget.SeekBar; import android.widget.Spinner; import android.widget.TextView; @@ -20,10 +22,11 @@ import eu.jnksoftware.discountfinderandroid.Apis.ApiUtils; import eu.jnksoftware.discountfinderandroid.R; +import eu.jnksoftware.discountfinderandroid.Utilities.ManageSharePrefs; import eu.jnksoftware.discountfinderandroid.models.Category; import eu.jnksoftware.discountfinderandroid.models.discountPreferences.DiscountPreferencesPostResponse; import eu.jnksoftware.discountfinderandroid.models.discountPreferences.DiscountPreferencesRequest; -import eu.jnksoftware.discountfinderandroid.models.token.UserTokenResponse; +import eu.jnksoftware.discountfinderandroid.models.token.User; import eu.jnksoftware.discountfinderandroid.services.IuserService; import retrofit2.Call; import retrofit2.Callback; @@ -31,27 +34,29 @@ public class UserPreferences extends AppCompatActivity { - private UserTokenResponse userTokenResponse; + private User user; private int seekBarProgress = 0; private TextView showSeekProgress; private List categories = new ArrayList<>(); + private List catTemp = new ArrayList<>(); IuserService iuserService; String accessToken; private ArrayAdapter spinContentAdapter; private Spinner spinnerCat; + private String auth; + private EditText tags; @SuppressLint("SetTextI18n") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_user_preferences); - String accessToken; iuserService= ApiUtils.getUserService(); + user = ManageSharePrefs.readUser(null); + tags=findViewById(R.id.textTag); + - Gson user = new Gson(); - userTokenResponse = user.fromJson(getIntent().getStringExtra("User"),UserTokenResponse.class); - Toast.makeText(UserPreferences.this, "token"+userTokenResponse.getTokenType(), Toast.LENGTH_LONG).show(); spinnerCat = findViewById(R.id.spinnerCategory); spinContentAdapter = new ArrayAdapter<>(UserPreferences.this,android.R.layout.simple_list_item_1, catTemp); @@ -63,6 +68,7 @@ protected void onCreate(Bundle savedInstanceState) { SeekBar seekBarPrice = findViewById(R.id.seekBarPrice); showSeekProgress = findViewById(R.id.tvSeekBarValue); + Button savePrefButton = findViewById(R.id.btSavePreferences); savePrefButton.setOnClickListener(savePrefClick); @@ -97,16 +103,16 @@ public void onClick(View view) { DiscountPreferencesRequest discountPreferencesRequest=new DiscountPreferencesRequest(); discountPreferencesRequest.setCategory(String.valueOf(categories.get((int) spinnerCat.getSelectedItemId()).getId())); discountPreferencesRequest.setPrice(String.valueOf(seekBarProgress)); - discountPreferencesRequest.setTags("Sample"); - String auth; - auth="Bearer "+userTokenResponse.getAccessToken(); - doUserPreference(discountPreferencesRequest,auth); + discountPreferencesRequest.setTags(tags.getText().toString()); + + + doUserPreference(discountPreferencesRequest); Toast.makeText(UserPreferences.this, discountPreferencesRequest.getCategory(), Toast.LENGTH_SHORT).show(); } }; - public void doUserPreference(final DiscountPreferencesRequest discountPreferencesRequest,String auth) { - + public void doUserPreference(final DiscountPreferencesRequest discountPreferencesRequest) { + auth="Bearer "+user.getAccessToken(); Call call = iuserService.postDiscountPreferences(discountPreferencesRequest,auth); call.enqueue(new Callback() { @Override @@ -152,10 +158,7 @@ public void onFailure(Call> call, Throwable t) { }); } - @Override - public void onBackPressed() { - super.onBackPressed(); - Intent intent=new Intent(UserPreferences.this,UserPreferenceList.class); - startActivity(intent); - } + + + } \ No newline at end of file diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/userPreferences/UserUpdatePreferences.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/userPreferences/UserUpdatePreferences.java index 5c19036..8b77687 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/userPreferences/UserUpdatePreferences.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/customer/userPreferences/UserUpdatePreferences.java @@ -23,7 +23,7 @@ import eu.jnksoftware.discountfinderandroid.models.Category; import eu.jnksoftware.discountfinderandroid.models.discountPreferences.DiscountPreferencesRequest; import eu.jnksoftware.discountfinderandroid.models.discountPreferences.DiscountPreferencesResponse; -import eu.jnksoftware.discountfinderandroid.models.token.UserTokenResponse; +import eu.jnksoftware.discountfinderandroid.models.token.User; import eu.jnksoftware.discountfinderandroid.services.IuserService; import retrofit2.Call; import retrofit2.Callback; @@ -31,7 +31,7 @@ public class UserUpdatePreferences extends AppCompatActivity { - private UserTokenResponse userTokenResponse; + private User user; private int seekBarProgress = 0; private TextView showSeekProgress; private List categories = new ArrayList<>(); @@ -53,8 +53,8 @@ protected void onCreate(Bundle savedInstanceState) { idUpdatePref =findViewById(R.id.idPrefText); tagUpdatePref=findViewById(R.id.tagPrefText); Gson user = new Gson(); - userTokenResponse = user.fromJson(getIntent().getStringExtra("User"),UserTokenResponse.class); - Toast.makeText(getApplicationContext(), "token"+userTokenResponse.getTokenType(), Toast.LENGTH_LONG).show(); + this.user = user.fromJson(getIntent().getStringExtra("User"),User.class); + Toast.makeText(getApplicationContext(), "token"+ this.user.getTokenType(), Toast.LENGTH_LONG).show(); spinnerCat = findViewById(R.id.spinnerCategory); spinContentAdapter = new ArrayAdapter<>(UserUpdatePreferences.this,android.R.layout.simple_list_item_1, catTemp); @@ -108,7 +108,7 @@ public void onClick(View view) { s1=idUpdatePref.getText().toString(); idpref=Integer.parseInt(s1); String auth; - auth="Bearer "+userTokenResponse.getAccessToken(); + auth="Bearer "+ user.getAccessToken(); //Toast.makeText(UserUpdatePreferences.this,auth,Toast.LENGTH_SHORT).show(); doUpdateUserPreference(idpref,discountPreferencesRequest,auth); diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/general/Login.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/general/Login.java index 66dbc8b..d68a4b7 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/general/Login.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/general/Login.java @@ -13,14 +13,15 @@ import android.widget.Toast; import com.google.firebase.iid.FirebaseInstanceId; -import com.google.gson.Gson; import eu.jnksoftware.discountfinderandroid.Apis.ApiUtils; +import eu.jnksoftware.discountfinderandroid.Apis.HttpCall; +import eu.jnksoftware.discountfinderandroid.CustomerMenu; import eu.jnksoftware.discountfinderandroid.R; -import eu.jnksoftware.discountfinderandroid.models.token.UserTokenRequest; -import eu.jnksoftware.discountfinderandroid.models.token.UserTokenResponse; +import eu.jnksoftware.discountfinderandroid.Utilities.ManageSharePrefs; +import eu.jnksoftware.discountfinderandroid.models.token.FcmToken; +import eu.jnksoftware.discountfinderandroid.models.token.User; import eu.jnksoftware.discountfinderandroid.services.IuserService; -import eu.jnksoftware.discountfinderandroid.ui.customer.MenuCustomer; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; @@ -33,15 +34,19 @@ public class Login extends Activity { private EditText eMail; private EditText password; IuserService iuserService; + private String username; + private String pass; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); - eMail= findViewById(R.id.loginEMailField); - password=findViewById(R.id.loginPasswordField); - iuserService= ApiUtils.getUserService(); - String token = FirebaseInstanceId.getInstance().getToken(); + eMail = findViewById(R.id.loginEMailField); + password = findViewById(R.id.loginPasswordField); + eMail.setText("user@jnksoftware.eu"); + password.setText("myPassword"); + iuserService = ApiUtils.getUserService(); Button login = findViewById(R.id.loginBtn); login.setOnClickListener(loginBtnClick); @@ -51,16 +56,31 @@ protected void onCreate(Bundle savedInstanceState) { loadingText = findViewById(R.id.loadingText); loadingBar = findViewById(R.id.loadingBar); + ManageSharePrefs.init(getApplicationContext()); + + + + User userFromPrefs = ManageSharePrefs.readUser(null); + if (userFromPrefs != null) { + Toast.makeText(Login.this, "wowooww" + userFromPrefs.getTokenType(), Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(Login.this, "nothing", Toast.LENGTH_SHORT).show(); + } + + } private final View.OnClickListener loginBtnClick = new View.OnClickListener() { @Override public void onClick(final View loginView) { + int response; + + username=eMail.getText().toString(); + pass=password.getText().toString(); - UserTokenRequest userTokenRequest=new UserTokenRequest(); - userTokenRequest.setUsername(eMail.getText().toString().trim()); - userTokenRequest.setPassword(password.getText().toString().trim()); - doLogin(userTokenRequest); + /* userTokenRequest.setUsername(eMail.getText().toString().trim()); + userTokenRequest.setPassword(password.getText().toString().trim());*/ + doLogin(username,pass); loadingBar.setVisibility(View.VISIBLE); loadingText.setVisibility(View.VISIBLE); loadingText.setText("Please Wait..."); @@ -77,37 +97,52 @@ public void onClick(final View registerView) { }; - public void doLogin(final UserTokenRequest userTokenRequest){ - Call call=iuserService.getTokenAcess(userTokenRequest); - call.enqueue(new Callback() { - @Override - public void onResponse(Call call, Response response) { - if(response.isSuccessful()) - { - UserTokenResponse userTokenResponse=response.body(); - - Gson user=new Gson(); - Intent menuCustomer = new Intent(Login.this, MenuCustomer.class); - menuCustomer.putExtra("User", user.toJson(userTokenResponse)); - startActivity(menuCustomer); + public void doLogin(String username,String password) { + Call call = iuserService.login(username,password); + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + + User userTokenResponse = response.body(); + + Intent menuCustomer = new Intent(Login.this, CustomerMenu.class); + menuCustomer.putExtra("email",eMail.getText().toString()); + + String fcmTokenDataString = ManageSharePrefs.readFcmTokenData(""); + + if (userTokenResponse.getAccessToken().equals(fcmTokenDataString)) { + startActivity(menuCustomer); + } else { + ManageSharePrefs.writeUser(userTokenResponse); + FcmToken token = new FcmToken(FirebaseInstanceId.getInstance().getToken()); + HttpCall httpCall = new HttpCall(); + int statusCode; + statusCode = httpCall.setFcmToken(token, userTokenResponse.getTokenType() + " " + userTokenResponse.getAccessToken()); + if (statusCode == 200) { + ManageSharePrefs.writeFcmTokenData(userTokenResponse.getAccessToken()); + } + startActivity(menuCustomer); + } + } else { + Toast.makeText(Login.this, "" + response.message(), Toast.LENGTH_SHORT).show(); } - else - { - Toast.makeText(Login.this,""+response.message(),Toast.LENGTH_SHORT).show(); - } + } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { call.cancel(); - Log.d("MaincActivity","onFailure"+t.getMessage()); - Toast.makeText(Login.this,"Wrong!"+t.getMessage(),Toast.LENGTH_SHORT).show(); + Log.d("MainActivity", "onFailure" + t.getMessage()); + Toast.makeText(Login.this, "Wrong!" + t.getMessage(), Toast.LENGTH_SHORT).show(); } }); + } + private class aSyncTask extends AsyncTask { @Override @@ -118,7 +153,7 @@ protected void onPreExecute() { @Override protected String doInBackground(String... strings) { - for (loadingStatus=0; loadingStatus < 50; loadingStatus++) { + for (loadingStatus = 0; loadingStatus < 50; loadingStatus++) { try { Thread.sleep(80); } catch (InterruptedException e) { @@ -147,8 +182,10 @@ protected void onPostExecute(String s) { Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show(); loadingBar.setVisibility(View.INVISIBLE); loadingText.setText(s); + loadingText.setVisibility(View.INVISIBLE); } } + } diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/general/Main.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/general/Main.java index bab416a..8efb912 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/general/Main.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/general/Main.java @@ -12,6 +12,7 @@ import eu.jnksoftware.discountfinderandroid.R; import eu.jnksoftware.discountfinderandroid.services.GeoLocation; + public class Main extends AppCompatActivity { private GeoLocation geoLocation; diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/general/Register.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/general/Register.java index 1c3789d..4853dcf 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/general/Register.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/general/Register.java @@ -11,8 +11,7 @@ import eu.jnksoftware.discountfinderandroid.Apis.ApiUtils; import eu.jnksoftware.discountfinderandroid.R; -import eu.jnksoftware.discountfinderandroid.models.token.RegisterTokenRequest; -import eu.jnksoftware.discountfinderandroid.models.token.UserTokenResponse; +import eu.jnksoftware.discountfinderandroid.models.token.User; import eu.jnksoftware.discountfinderandroid.services.IuserService; import retrofit2.Call; import retrofit2.Callback; @@ -24,6 +23,10 @@ public class Register extends Activity { private EditText password; private EditText firstName; private EditText lastName; + private String mail; + private String fName; + private String lName; + private String pass; IuserService iuserService; @Override protected void onCreate(Bundle savedInstanceState) { @@ -44,12 +47,12 @@ protected void onCreate(Bundle savedInstanceState) { public void onClick(final View reg) { - RegisterTokenRequest registerTokenRequest=new RegisterTokenRequest(); - registerTokenRequest.setEMail(eMail.getText().toString().trim()); - registerTokenRequest.setFirstName(firstName.getText().toString().trim()); - registerTokenRequest.setLastName(lastName.getText().toString().trim()); - registerTokenRequest.setPassword(password.getText().toString().trim()); - doRegister(registerTokenRequest); + + fName=firstName.getText().toString().trim(); + lName=lastName.getText().toString().trim(); + mail=eMail.getText().toString().trim(); + pass=password.getText().toString().trim(); + doRegister(fName,lName,mail,pass); @@ -57,11 +60,11 @@ public void onClick(final View reg) { } }; - public void doRegister(final RegisterTokenRequest registerTokenRequest){ - Call call=iuserService.register(registerTokenRequest); - call.enqueue(new Callback() { + public void doRegister(String fName,String lName,String mail,String pass){ + Call call=iuserService.register(fName,lName,mail,pass); + call.enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(Call call, Response response) { int statusCode=response.code(); @@ -79,7 +82,7 @@ public void onResponse(Call call, Response } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { call.cancel(); Log.d("MaincActivity","onFailure"+t.getMessage()); Toast.makeText(Register.this,"Wrong!"+t.getMessage(),Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/general/Settings.java b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/general/Settings.java index 491016f..bad3379 100644 --- a/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/general/Settings.java +++ b/app/src/main/java/eu/jnksoftware/discountfinderandroid/ui/general/Settings.java @@ -1,40 +1,39 @@ package eu.jnksoftware.discountfinderandroid.ui.general; -import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; -import android.widget.CheckBox; +import android.widget.Switch; +import android.widget.Toast; import eu.jnksoftware.discountfinderandroid.R; -import eu.jnksoftware.discountfinderandroid.ui.customer.MenuCustomer; +import eu.jnksoftware.discountfinderandroid.Utilities.ManageSharePrefs; public class Settings extends AppCompatActivity { + private Button backButton; + private Switch isSellerSwitch; + @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); + super.onCreate(savedInstanceState); - Button backButton = findViewById(R.id.backButton); + backButton = findViewById(R.id.settingsBackButton); backButton.setOnClickListener(backButtonClick); - - CheckBox sellerCheckBox = findViewById(R.id.sellerCheckBox); - boolean isEnabled = getIntent().getBooleanExtra("isSellerEnabled",false); - if(isEnabled){ - sellerCheckBox.setChecked(true); - } - else{ - sellerCheckBox.setChecked(false); - } + isSellerSwitch = findViewById(R.id.switchSettingsIsSeller); + isSellerSwitch.setChecked(ManageSharePrefs.readUserIsSeller(false)); } - private final View.OnClickListener backButtonClick = new View.OnClickListener() { + View.OnClickListener backButtonClick = new View.OnClickListener() { @Override - public void onClick(View v) { - Intent back = new Intent(Settings.this, MenuCustomer.class); - startActivity(back); + public void onClick(View view) { + ManageSharePrefs.writeUserIsSeller(isSellerSwitch.isChecked()); + Toast.makeText(getBaseContext(), "You have to restart the application for changes to be applied", Toast.LENGTH_LONG).show(); + finish(); } + }; + } diff --git a/app/src/main/res/drawable-nodpi/background.xml b/app/src/main/res/drawable-nodpi/background.xml deleted file mode 100644 index 3377b6e..0000000 --- a/app/src/main/res/drawable-nodpi/background.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable-nodpi/background_style_menu_customer.xml b/app/src/main/res/drawable-nodpi/background_style_menu_customer.xml deleted file mode 100644 index 802212e..0000000 --- a/app/src/main/res/drawable-nodpi/background_style_menu_customer.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable-v21/ic_menu_gallery.xml b/app/src/main/res/drawable-v21/ic_menu_gallery.xml new file mode 100644 index 0000000..f6872c4 --- /dev/null +++ b/app/src/main/res/drawable-v21/ic_menu_gallery.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable-nodpi/background_style.xml b/app/src/main/res/drawable/background_style.xml similarity index 100% rename from app/src/main/res/drawable-nodpi/background_style.xml rename to app/src/main/res/drawable/background_style.xml diff --git a/app/src/main/res/drawable/ic_back.png b/app/src/main/res/drawable/ic_back.png new file mode 100644 index 0000000..7315461 Binary files /dev/null and b/app/src/main/res/drawable/ic_back.png differ diff --git a/app/src/main/res/drawable/ic_menu_exit_to_app_black_24dp.png b/app/src/main/res/drawable/ic_menu_exit_to_app_black_24dp.png new file mode 100644 index 0000000..ad0f63e Binary files /dev/null and b/app/src/main/res/drawable/ic_menu_exit_to_app_black_24dp.png differ diff --git a/app/src/main/res/drawable/ic_menu_home.png b/app/src/main/res/drawable/ic_menu_home.png new file mode 100644 index 0000000..9f61d7b Binary files /dev/null and b/app/src/main/res/drawable/ic_menu_home.png differ diff --git a/app/src/main/res/drawable/ic_menu_info_black_24dp.png b/app/src/main/res/drawable/ic_menu_info_black_24dp.png new file mode 100644 index 0000000..da56077 Binary files /dev/null and b/app/src/main/res/drawable/ic_menu_info_black_24dp.png differ diff --git a/app/src/main/res/drawable/ic_menu_logout.png b/app/src/main/res/drawable/ic_menu_logout.png new file mode 100644 index 0000000..753cc74 Binary files /dev/null and b/app/src/main/res/drawable/ic_menu_logout.png differ diff --git a/app/src/main/res/drawable/ic_menu_offers.png b/app/src/main/res/drawable/ic_menu_offers.png new file mode 100644 index 0000000..7238564 Binary files /dev/null and b/app/src/main/res/drawable/ic_menu_offers.png differ diff --git a/app/src/main/res/drawable/ic_menu_preferences.png b/app/src/main/res/drawable/ic_menu_preferences.png new file mode 100644 index 0000000..da63e58 Binary files /dev/null and b/app/src/main/res/drawable/ic_menu_preferences.png differ diff --git a/app/src/main/res/drawable/ic_pin_drop_black_24dp.xml b/app/src/main/res/drawable/ic_pin_drop_black_24dp.xml new file mode 100644 index 0000000..49a3317 --- /dev/null +++ b/app/src/main/res/drawable/ic_pin_drop_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_settings_black_24dp.png b/app/src/main/res/drawable/ic_settings_black_24dp.png new file mode 100644 index 0000000..acf1ddf Binary files /dev/null and b/app/src/main/res/drawable/ic_settings_black_24dp.png differ diff --git a/app/src/main/res/drawable/ic_store_mall_directory_black_24dp.png b/app/src/main/res/drawable/ic_store_mall_directory_black_24dp.png new file mode 100644 index 0000000..a45c025 Binary files /dev/null and b/app/src/main/res/drawable/ic_store_mall_directory_black_24dp.png differ diff --git a/app/src/main/res/drawable/nav_header.jpg b/app/src/main/res/drawable/nav_header.jpg new file mode 100644 index 0000000..5d84bf7 Binary files /dev/null and b/app/src/main/res/drawable/nav_header.jpg differ diff --git a/app/src/main/res/drawable/side_nav_bar.xml b/app/src/main/res/drawable/side_nav_bar.xml new file mode 100644 index 0000000..6d81870 --- /dev/null +++ b/app/src/main/res/drawable/side_nav_bar.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_choose_store_location.xml b/app/src/main/res/layout/activity_choose_store_location.xml index 24697d0..0278d3e 100644 --- a/app/src/main/res/layout/activity_choose_store_location.xml +++ b/app/src/main/res/layout/activity_choose_store_location.xml @@ -1,4 +1,3 @@ - \ No newline at end of file + tools:context="eu.jnksoftware.discountfinderandroid.services.ChooseStoreLocation"> + + + + +