From 7c1d686be64139b29560962213b9c4fe4874855a Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Fri, 22 Feb 2019 20:52:00 +0400 Subject: [PATCH] Made favorites system --- .idea/assetWizardSettings.xml | 5 +- .idea/caches/gradle_models.ser | Bin 111999 -> 112002 bytes app/build.gradle | 6 +- app/src/main/AndroidManifest.xml | 21 +-- .../ru/volgorobot/vrcatalog/MainContract.java | 11 +- .../additional/DatabaseProperties.java | 11 ++ .../vrcatalog/additional/SqliteHelper.java | 27 ++++ .../adapters/FavoritesListAdapter.java | 23 ++++ .../adapters/ImagePagerAdapter.java | 4 +- .../vrcatalog/model/FavoritesListModel.java | 35 +++++ .../SecondLevelNodeViewBinder.java | 2 +- .../ThirdLevelNodeViewBinder.java | 2 +- .../presenters/FavoritesDBPresenter.java | 83 ++++++++++++ .../presenters/FavoritesPresenter.java | 77 +++++++++++ .../presenters/ViewBinderPresenter.java | 6 +- .../vrcatalog/view/FavoritesActivity.java | 121 ++++++++++++++++++ ...{DetailActivity.java => ItemActivity.java} | 69 ++++++++-- .../vrcatalog/view/MainActivity.java | 2 + .../res/drawable/ic_favorite_black_24dp.xml | 9 ++ .../ic_favorite_border_white_24dp.xml | 5 + .../res/drawable/ic_favorite_white_24dp.xml | 5 + .../main/res/layout/activity_favorites.xml | 14 ++ .../main/res/menu/activity_main_drawer.xml | 5 +- app/src/main/res/menu/item_activity_menu.xml | 16 +++ 24 files changed, 523 insertions(+), 36 deletions(-) create mode 100644 app/src/main/java/ru/volgorobot/vrcatalog/additional/DatabaseProperties.java create mode 100644 app/src/main/java/ru/volgorobot/vrcatalog/additional/SqliteHelper.java create mode 100644 app/src/main/java/ru/volgorobot/vrcatalog/additional/adapters/FavoritesListAdapter.java create mode 100644 app/src/main/java/ru/volgorobot/vrcatalog/model/FavoritesListModel.java create mode 100644 app/src/main/java/ru/volgorobot/vrcatalog/presenters/FavoritesDBPresenter.java create mode 100644 app/src/main/java/ru/volgorobot/vrcatalog/presenters/FavoritesPresenter.java create mode 100644 app/src/main/java/ru/volgorobot/vrcatalog/view/FavoritesActivity.java rename app/src/main/java/ru/volgorobot/vrcatalog/view/{DetailActivity.java => ItemActivity.java} (68%) create mode 100644 app/src/main/res/drawable/ic_favorite_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_favorite_border_white_24dp.xml create mode 100644 app/src/main/res/drawable/ic_favorite_white_24dp.xml create mode 100644 app/src/main/res/layout/activity_favorites.xml create mode 100644 app/src/main/res/menu/item_activity_menu.xml diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml index b600225..0f9fbd3 100644 --- a/.idea/assetWizardSettings.xml +++ b/.idea/assetWizardSettings.xml @@ -147,7 +147,7 @@ @@ -157,8 +157,7 @@ diff --git a/.idea/caches/gradle_models.ser b/.idea/caches/gradle_models.ser index 7b679832e0362ff6aca3af764c692ec06f3af29a..71bfa86d46602a2087a375406d138f2346ef7b4e 100644 GIT binary patch delta 17379 zcmc(HcYKt^*8ell?xq3Brji6nfdE1vh4esRO+r8jA)$A&ECCi%HpwO=v;{;;Xdxp! zQUt_{6d_1m1ySH4idU2<*89?wi`WqERRl$N&zYxfHXHBz`TYL)`NxwK3LQ7Mo)(F6u)UNAxB>^k_slX-7Ye zSVF(ydmJu|96^X5J<=(Lgwbz0Rd)!><@`!&bBc}CWfj@xlA_W|b6II+Ik$idqt?!E z16N|yYADY{#RdXz+mhN5wWX$~D=VvtBrdlu;n2Pj%PZsc8)Zz0_jv`PC?~zRObaam>_&aiXFr__0{kf?3KiL;-VS~zjPxTm)5Icc$ zt2P!(U}I}6qFe-{{$;Upx@kpIt7hPs2AUI{sf@oiy3T{^BcYA#xd4XT-ZQj4XzE>3 zo0V;@C^A{gD$KGintHa+g*M-k+QHxo=jL2402)fox#p>rE!#lgP-CfidQqhn{fAim zXkxFJ5D=&@sU2R_q7R+ht0Mr~*sDX7WYDy-v#&bZ0MsO`4#q8{O-V!O)>z+8M)S1d z**q6p(;DkknUxMs)cZ>IRAtfp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(#!oHQY0L?pD*tVGj8ujNs zSseK@L?Zlb2b>J|$Y8qFBU|4B%f0%y_n!PC1D{wtKqK<$-#gHBtU#r~CzqR&I9MlH z0^G&+s&abM>cTEAFT#jNbeH;GNx;0~atq}v7qKoMu@t}+I{xAgxHv1a+Wp=RX{A-- z53A4_VkmQqP%ekRH-Mko;m5~6*q6q#kQ`2+svbKqCvnTLsm5kGHY>1MiOp(kYOtxr z=2K|c>|E1g`6p6~2oXZ-$&bWK@H$MEk``h8VFG`zLpUJ*_s(IG0#6=C$aIYO5%9~` zp~9gfQTo*Di|MV84npBcABc&>p21i|IH_$vx03|AV6?-=-*1^j^v zC*#?lub2RTH=&i(OpQPM@e`oJ4>O#Ij5$hTiN7%SD2YO-qZrgLkCOJ@Qm#fDNOuSV a{2`Q49T~w{BbZ(x0d8O>=ydsQ@&5qjYF2Up diff --git a/app/build.gradle b/app/build.gradle index dffabc9..0c63f7e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "ru.volgorobot.vrcatalog" minSdkVersion 19 targetSdkVersion 27 - versionCode 5 - versionName "0.3.1" + versionCode 7 + versionName "0.5alpha" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } compileOptions { @@ -35,4 +35,4 @@ dependencies { implementation 'com.android.support:recyclerview-v7:27.1.1' implementation 'com.squareup.picasso:picasso:2.71828' implementation 'com.github.chrisbanes:PhotoView:2.1.4' -} \ No newline at end of file +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ac11670..371f056 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - @@ -12,6 +11,7 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> + + android:theme="@style/AppTheme.Fullscreen" /> + android:name=".view.ItemActivity" + android:theme="@style/ItemActivityTheme" /> + android:parentActivityName=".view.MainActivity"> + - + - diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/MainContract.java b/app/src/main/java/ru/volgorobot/vrcatalog/MainContract.java index 62247c0..991ebef 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/MainContract.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/MainContract.java @@ -27,12 +27,21 @@ public interface MainContract { CoreModel getCoreModel(); } - interface ViewBinderPresenter { + interface LevelLoaderPresenter { void fetchSecondLevel(FirstLevelModel firstLevelModel, TreeNode treeNode); void fetchThirdLevel(SecondLevelModel secondLevelModel, TreeNode treeNode); void fetchDetail(ThirdLevelModel thirdLevelModel); } + interface FavoritesPresenter { + void fetchItem(int itemID); + } + + interface FavoritesActivityView { + void onFailruleAnswer(int errorCode); + void startActivityByIntent(Intent intent); + } + interface ViewBinder { void rotateImageView(); } diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/additional/DatabaseProperties.java b/app/src/main/java/ru/volgorobot/vrcatalog/additional/DatabaseProperties.java new file mode 100644 index 0000000..b5165df --- /dev/null +++ b/app/src/main/java/ru/volgorobot/vrcatalog/additional/DatabaseProperties.java @@ -0,0 +1,11 @@ +package ru.volgorobot.vrcatalog.additional; + +public class DatabaseProperties { + public final static String DATABASE_NAME = "database"; + public final static String FAVORITES_TABLE_NAME = "favorites"; + public final static int DATABASE_VERSION = 1; + + public final static String FAVORITES_COLUMN_ID = "_id"; + public final static String FAVORITES_COLUMN_ITEM_ID = "itemID"; + public final static String FAVORITES_COLUMN_ITEM_NAME = "itemName"; +} diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/additional/SqliteHelper.java b/app/src/main/java/ru/volgorobot/vrcatalog/additional/SqliteHelper.java new file mode 100644 index 0000000..02148f2 --- /dev/null +++ b/app/src/main/java/ru/volgorobot/vrcatalog/additional/SqliteHelper.java @@ -0,0 +1,27 @@ +package ru.volgorobot.vrcatalog.additional; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; + +public class SqliteHelper extends SQLiteOpenHelper { + public SqliteHelper(Context context) { + super(context, DatabaseProperties.DATABASE_NAME, null, DatabaseProperties.DATABASE_VERSION); + } + + @Override + public void onCreate(SQLiteDatabase sqLiteDatabase) { + String query = "CREATE TABLE " + + DatabaseProperties.FAVORITES_TABLE_NAME + "(" + + DatabaseProperties.FAVORITES_COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + + DatabaseProperties.FAVORITES_COLUMN_ITEM_ID + " INTEGER," + + DatabaseProperties.FAVORITES_COLUMN_ITEM_NAME + " TEXT);"; + sqLiteDatabase.execSQL(query); + } + + @Override + public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { + sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + DatabaseProperties.FAVORITES_TABLE_NAME); + onCreate(sqLiteDatabase); + } +} diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/additional/adapters/FavoritesListAdapter.java b/app/src/main/java/ru/volgorobot/vrcatalog/additional/adapters/FavoritesListAdapter.java new file mode 100644 index 0000000..49395d5 --- /dev/null +++ b/app/src/main/java/ru/volgorobot/vrcatalog/additional/adapters/FavoritesListAdapter.java @@ -0,0 +1,23 @@ +package ru.volgorobot.vrcatalog.additional.adapters; + +import android.content.Context; +import android.widget.ArrayAdapter; + +import java.util.List; + +import ru.volgorobot.vrcatalog.model.FavoritesListModel; +import ru.volgorobot.vrcatalog.presenters.FavoritesDBPresenter; + +public class FavoritesListAdapter extends ArrayAdapter { + private FavoritesDBPresenter db; + + public FavoritesListAdapter(Context context, int resource, List objects) { + super(context, resource, objects); + db = new FavoritesDBPresenter(context); + } + + public void updateData() { + super.clear(); + super.addAll(db.selectAll()); + } +} diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/additional/adapters/ImagePagerAdapter.java b/app/src/main/java/ru/volgorobot/vrcatalog/additional/adapters/ImagePagerAdapter.java index 506f8eb..2f182f9 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/additional/adapters/ImagePagerAdapter.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/additional/adapters/ImagePagerAdapter.java @@ -13,16 +13,14 @@ import android.widget.ImageView; import com.squareup.picasso.Picasso; -import java.io.FileNotFoundException; import java.io.IOException; import ru.volgorobot.vrcatalog.R; -import ru.volgorobot.vrcatalog.view.DetailActivity; import ru.volgorobot.vrcatalog.view.FullScreenImageActivity; public class ImagePagerAdapter extends PagerAdapter { /** - * This class is designed to control the ViewPager (images of item) in the activity of viewing details of items (DetailActivity). + * This class is designed to control the ViewPager (images of item) in the activity of viewing details of items (ItemActivity). */ private Context context; diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/model/FavoritesListModel.java b/app/src/main/java/ru/volgorobot/vrcatalog/model/FavoritesListModel.java new file mode 100644 index 0000000..75cfb7b --- /dev/null +++ b/app/src/main/java/ru/volgorobot/vrcatalog/model/FavoritesListModel.java @@ -0,0 +1,35 @@ +package ru.volgorobot.vrcatalog.model; + +public class FavoritesListModel { + private int id; + private int itemID; + private String itemName; + + public FavoritesListModel(int itemID, String itemName) { + this.itemID = itemID; + this.itemName = itemName; + } + + public FavoritesListModel(int id, int itemID, String itemName) { + this.id = id; + this.itemID = itemID; + this.itemName = itemName; + } + + public int getItemID() { + return itemID; + } + + public String getItemName() { + return itemName; + } + + public int getID() { + return id; + } + + @Override + public String toString() { + return getItemName(); + } +} diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/SecondLevelNodeViewBinder.java b/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/SecondLevelNodeViewBinder.java index c42b182..9dacb60 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/SecondLevelNodeViewBinder.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/SecondLevelNodeViewBinder.java @@ -15,7 +15,7 @@ import ru.volgorobot.vrcatalog.model.SecondLevelModel; public class SecondLevelNodeViewBinder extends BaseNodeViewBinder implements MainContract.ViewBinder { TextView textView; ImageView imageView; - MainContract.ViewBinderPresenter viewBinderPresenter; + MainContract.LevelLoaderPresenter viewBinderPresenter; public SecondLevelNodeViewBinder(View itemView, MainContract.MainActivityView mView, Context context) { diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/ThirdLevelNodeViewBinder.java b/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/ThirdLevelNodeViewBinder.java index 036fac0..f18c3e6 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/ThirdLevelNodeViewBinder.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/nodeViewBinders/ThirdLevelNodeViewBinder.java @@ -13,7 +13,7 @@ import ru.volgorobot.vrcatalog.model.ThirdLevelModel; public class ThirdLevelNodeViewBinder extends BaseNodeViewBinder implements MainContract.ViewBinder { TextView textView; - MainContract.ViewBinderPresenter viewBinderPresenter; + MainContract.LevelLoaderPresenter viewBinderPresenter; public ThirdLevelNodeViewBinder(View itemView, Context context, MainContract.MainActivityView mView) { super(itemView); diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/presenters/FavoritesDBPresenter.java b/app/src/main/java/ru/volgorobot/vrcatalog/presenters/FavoritesDBPresenter.java new file mode 100644 index 0000000..ba5e70c --- /dev/null +++ b/app/src/main/java/ru/volgorobot/vrcatalog/presenters/FavoritesDBPresenter.java @@ -0,0 +1,83 @@ +package ru.volgorobot.vrcatalog.presenters; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; + +import java.util.ArrayList; + +import ru.volgorobot.vrcatalog.additional.DatabaseProperties; +import ru.volgorobot.vrcatalog.additional.SqliteHelper; +import ru.volgorobot.vrcatalog.model.FavoritesListModel; + +public class FavoritesDBPresenter { + private SqliteHelper mHelper; + private SQLiteDatabase mDB; + + public FavoritesDBPresenter(Context context) { + this.mHelper = new SqliteHelper(context); + this.mDB = mHelper.getWritableDatabase(); + } + + public ArrayList selectAll() { + ArrayList models = new ArrayList<>(); + + String[] columns = { + DatabaseProperties.FAVORITES_COLUMN_ID, + DatabaseProperties.FAVORITES_COLUMN_ITEM_ID, + DatabaseProperties.FAVORITES_COLUMN_ITEM_NAME + }; + + Cursor cursor = mDB.query(DatabaseProperties.FAVORITES_TABLE_NAME, columns, null, null, null, null, null); + + if(cursor == null) + return new ArrayList<>(); + + while(cursor.moveToNext()) { + models.add(new FavoritesListModel( + cursor.getInt(cursor.getColumnIndex(DatabaseProperties.FAVORITES_COLUMN_ID)), + cursor.getInt(cursor.getColumnIndex(DatabaseProperties.FAVORITES_COLUMN_ITEM_ID)), + cursor.getString(cursor.getColumnIndex(DatabaseProperties.FAVORITES_COLUMN_ITEM_NAME)))); + } + + cursor.close(); + + return models; + } + + public void add(FavoritesListModel model) { + ContentValues contentValues = new ContentValues(); + contentValues.put(DatabaseProperties.FAVORITES_COLUMN_ITEM_ID, model.getItemID()); + contentValues.put(DatabaseProperties.FAVORITES_COLUMN_ITEM_NAME, model.getItemName()); + mDB.insert(DatabaseProperties.FAVORITES_TABLE_NAME, null, contentValues); + } + + public void removeItem(int id) { + mDB.delete(DatabaseProperties.FAVORITES_TABLE_NAME, "_id = " + id, null); + } + + public boolean inFavoritesList(int itemID) { + String[] columns = { DatabaseProperties.FAVORITES_COLUMN_ITEM_ID }; + String[] selectionArgs = { Integer.toString(itemID) }; + Cursor cursor = mDB.query(DatabaseProperties.FAVORITES_TABLE_NAME, columns, DatabaseProperties.FAVORITES_COLUMN_ITEM_ID + " = ?", selectionArgs, null, null, null); + while(cursor.moveToNext()) { + if(cursor.getInt(cursor.getColumnIndex(DatabaseProperties.FAVORITES_COLUMN_ITEM_ID)) == itemID) + return true; + } + cursor.close(); + + return false; + } + + public int getFavoriteID(int itemID) { + String[] columns = { DatabaseProperties.FAVORITES_COLUMN_ID, DatabaseProperties.FAVORITES_COLUMN_ITEM_ID }; + Cursor cursor = mDB.query(DatabaseProperties.FAVORITES_TABLE_NAME, columns, DatabaseProperties.FAVORITES_COLUMN_ITEM_ID + " = " + Integer.toString(itemID), null, null, null, null); + int id = 0; + if( cursor != null && cursor.moveToFirst() ){ + id = cursor.getInt(cursor.getColumnIndex(DatabaseProperties.FAVORITES_COLUMN_ID)); + cursor.close(); + } + return id; + } +} diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/presenters/FavoritesPresenter.java b/app/src/main/java/ru/volgorobot/vrcatalog/presenters/FavoritesPresenter.java new file mode 100644 index 0000000..d61fb58 --- /dev/null +++ b/app/src/main/java/ru/volgorobot/vrcatalog/presenters/FavoritesPresenter.java @@ -0,0 +1,77 @@ +package ru.volgorobot.vrcatalog.presenters; + +import android.content.Context; +import android.content.Intent; +import android.os.AsyncTask; + +import java.util.ArrayList; + +import ru.volgorobot.vrcatalog.MainContract; +import ru.volgorobot.vrcatalog.additional.NetworkErrorException; +import ru.volgorobot.vrcatalog.additional.ResultWithErrorCode; +import ru.volgorobot.vrcatalog.model.CoreModel; +import ru.volgorobot.vrcatalog.model.DetailModel; +import ru.volgorobot.vrcatalog.view.FavoritesActivity; +import ru.volgorobot.vrcatalog.view.ItemActivity; + +public class FavoritesPresenter implements MainContract.FavoritesPresenter { + private Context mContext; + private MainContract.MainModel mainModel; + private MainContract.FavoritesActivityView mView; + + public FavoritesPresenter(Context context, FavoritesActivity view) { + this.mContext = context; + this.mainModel = new CoreModel(context); + this.mView = view; + } + + @Override + public void fetchItem(int itemID) { + new AsyncTask>() { + @Override + protected ResultWithErrorCode doInBackground(Integer... integers) { + ArrayList detail = null; + try { + detail = mainModel.fetchDetailByID(integers[0]); + } catch (NetworkErrorException networkErrorException) { + return new ResultWithErrorCode<>(detail.get(0), networkErrorException.getErrorCode()); + } catch (NullPointerException nullPointerException) { + return new ResultWithErrorCode<>(detail.get(0), 3); + } + return new ResultWithErrorCode<>(detail.get(0), 0); + } + + @Override + protected void onPostExecute(ResultWithErrorCode result) { + super.onPostExecute(result); + switch (result.getErrorCode()) { + case 0: { + Intent intent = new Intent(mContext, ItemActivity.class); + intent.putExtra("itemID", result.getData().getID().toString()); + intent.putExtra("detailName", result.getData().getName()); + intent.putExtra("detailQuantity", result.getData().getNumber().toString()); + intent.putExtra("detailPrice", result.getData().getPrice()); + intent.putExtra("detailCountry", result.getData().getCountry()); + intent.putExtra("detailAnalogue", result.getData().getAnalogue()); + intent.putExtra("detailDatasheet", result.getData().getDocURL()); + intent.putExtra("detailNotes", result.getData().getNotes()); + mView.startActivityByIntent(intent); + break; + } + case 1: { + mView.onFailruleAnswer(1); + break; + } + case 2: { + mView.onFailruleAnswer(2); + break; + } + case 3: { + mView.onFailruleAnswer(3); + break; + } + } + } + }.execute(itemID); + } +} diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/presenters/ViewBinderPresenter.java b/app/src/main/java/ru/volgorobot/vrcatalog/presenters/ViewBinderPresenter.java index fd5f3a8..0c26546 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/presenters/ViewBinderPresenter.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/presenters/ViewBinderPresenter.java @@ -15,9 +15,9 @@ import ru.volgorobot.vrcatalog.model.DetailModel; import ru.volgorobot.vrcatalog.model.FirstLevelModel; import ru.volgorobot.vrcatalog.model.SecondLevelModel; import ru.volgorobot.vrcatalog.model.ThirdLevelModel; -import ru.volgorobot.vrcatalog.view.DetailActivity; +import ru.volgorobot.vrcatalog.view.ItemActivity; -public class ViewBinderPresenter implements MainContract.ViewBinderPresenter { +public class ViewBinderPresenter implements MainContract.LevelLoaderPresenter { private MainContract.MainActivityView mView; private MainContract.MainModel coreModel; private MainContract.ViewBinder viewBinder; @@ -170,7 +170,7 @@ public class ViewBinderPresenter implements MainContract.ViewBinderPresenter { super.onPostExecute(result); switch (result.getErrorCode()) { case 0: { - Intent intent = new Intent(context, DetailActivity.class); + Intent intent = new Intent(context, ItemActivity.class); intent.putExtra("itemID", result.getData().getID().toString()); intent.putExtra("detailName", result.getData().getName()); intent.putExtra("detailQuantity", result.getData().getNumber().toString()); diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/view/FavoritesActivity.java b/app/src/main/java/ru/volgorobot/vrcatalog/view/FavoritesActivity.java new file mode 100644 index 0000000..e0fc419 --- /dev/null +++ b/app/src/main/java/ru/volgorobot/vrcatalog/view/FavoritesActivity.java @@ -0,0 +1,121 @@ +package ru.volgorobot.vrcatalog.view; + +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.ContextMenu; +import android.view.MenuItem; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ListView; +import android.widget.Toast; + +import java.util.ArrayList; + +import ru.volgorobot.vrcatalog.MainContract; +import ru.volgorobot.vrcatalog.R; +import ru.volgorobot.vrcatalog.additional.adapters.FavoritesListAdapter; +import ru.volgorobot.vrcatalog.model.FavoritesListModel; +import ru.volgorobot.vrcatalog.presenters.FavoritesDBPresenter; +import ru.volgorobot.vrcatalog.presenters.FavoritesPresenter; + +public class FavoritesActivity extends AppCompatActivity implements MainContract.FavoritesActivityView { + private FavoritesDBPresenter db; + private ListView listView; + private FavoritesListAdapter adapter; + private MainContract.FavoritesPresenter mPresenter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_favorites); + + mPresenter = new FavoritesPresenter(FavoritesActivity.this, this); + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + + db = new FavoritesDBPresenter(FavoritesActivity.this); + listView = findViewById(R.id.favorites_list_view); + registerForContextMenu(listView); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int i, long l) { + FavoritesListModel model = (FavoritesListModel) listView.getItemAtPosition(i); + mPresenter.fetchItem(model.getItemID()); + } + }); + + ArrayList models = db.selectAll(); + adapter = new FavoritesListAdapter(FavoritesActivity.this, android.R.layout.simple_list_item_1, models); + listView.setAdapter(adapter); + } + + @Override + public boolean onContextItemSelected(MenuItem item) { + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); + switch (item.getItemId()) { + case 0: { + FavoritesListModel model = (FavoritesListModel) listView.getItemAtPosition(info.position); + db.removeItem(model.getID()); + updateListView(); + } + } + return true; + } + + private void updateListView() { + adapter.updateData(); + adapter.notifyDataSetChanged(); + } + + @Override + public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { + if (v.getId() == R.id.favorites_list_view) { + menu.add(0, 0, 0,"Удалить"); + } + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch(item.getItemId()) { + case android.R.id.home: + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } + + @Override + public void onFailruleAnswer(int errorCode) { + switch (errorCode) { + case 1: { + Toast.makeText(FavoritesActivity.this, "Ошибка сети. Проверьте подключение к сети или данные подключения к API!", Toast.LENGTH_LONG).show(); + Log.e("FavoritesActivity", "Network Error! Re-check your connection credentials or network settings!"); + break; + } + case 2: { + Toast.makeText(FavoritesActivity.this, "Ответ от сервера неверен! Перепроверьте данные подключения!", Toast.LENGTH_LONG).show(); + Log.e("FavoritesActivity", "Answer of server is wrong! Re-check your connection credentials!"); + break; + } + case 3: { + Toast.makeText(FavoritesActivity.this, "Вы ввели неверный URL. Пример: http://example.ru", Toast.LENGTH_LONG).show(); + Log.e("MainActivity", "Invalid-formatted URL. Please, check URL (change his if it need) and try again."); + break; + } + } + } + + @Override + public void startActivityByIntent(Intent intent) { + startActivity(intent); + } + + @Override + protected void onResume() { + super.onResume(); + updateListView(); + } +} diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/view/DetailActivity.java b/app/src/main/java/ru/volgorobot/vrcatalog/view/ItemActivity.java similarity index 68% rename from app/src/main/java/ru/volgorobot/vrcatalog/view/DetailActivity.java rename to app/src/main/java/ru/volgorobot/vrcatalog/view/ItemActivity.java index 98b3870..c9154e5 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/view/DetailActivity.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/view/ItemActivity.java @@ -9,24 +9,33 @@ import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; +import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import java.util.LinkedHashMap; +import java.util.Map; +import ru.volgorobot.vrcatalog.model.FavoritesListModel; +import ru.volgorobot.vrcatalog.presenters.FavoritesDBPresenter; import ru.volgorobot.vrcatalog.presenters.ItemPresenter; import ru.volgorobot.vrcatalog.MainContract; import ru.volgorobot.vrcatalog.R; import ru.volgorobot.vrcatalog.additional.adapters.ImagePagerAdapter; import ru.volgorobot.vrcatalog.additional.adapters.PropertiesListAdapter; -public class DetailActivity extends AppCompatActivity implements MainContract.ItemView { +public class ItemActivity extends AppCompatActivity implements MainContract.ItemView { private MainContract.ItemPresenter mPresenter; private ViewPager viewPager; private ListView propertiesList; private ImagePagerAdapter imagePagerAdapter; + private boolean inFavorites; + private FavoritesDBPresenter db; + private int itemID; + private String itemName; @Override protected void onCreate(Bundle savedInstanceState) { @@ -38,10 +47,11 @@ public class DetailActivity extends AppCompatActivity implements MainContract.It getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(false); initializeViews(); - mPresenter = new ItemPresenter(DetailActivity.this, this); + mPresenter = new ItemPresenter(ItemActivity.this, this); Intent intent = getIntent(); - ((TextView) findViewById(R.id.itemName)).setText(intent.getStringExtra("detailName")); + itemName = intent.getStringExtra("detailName"); + ((TextView) findViewById(R.id.itemName)).setText(itemName); String tmp = intent.getStringExtra("detailPrice"); if(tmp.equals("0")) { tmp = "Уточните у продавца"; @@ -50,13 +60,18 @@ public class DetailActivity extends AppCompatActivity implements MainContract.It } ((TextView) findViewById(R.id.itemPrice)).setText(tmp); - LinkedHashMap extrasMap = getIntentExtras(intent); + LinkedHashMap intentDataForListView = getIntentExtras(intent); + itemID = Integer.parseInt(intent.getStringExtra("itemID")); + intentDataForListView.get("detailName"); + db = new FavoritesDBPresenter(ItemActivity.this); propertiesList = findViewById(R.id.propertiesList); - PropertiesListAdapter propertiesListAdapter = new PropertiesListAdapter(extrasMap); + PropertiesListAdapter propertiesListAdapter = new PropertiesListAdapter(intentDataForListView); propertiesList.setAdapter(propertiesListAdapter); mPresenter.getImagesByItemID(Integer.parseInt(intent.getStringExtra("itemID"))); + + inFavorites = db.inFavoritesList(itemID); } void initializeViews() { @@ -116,18 +131,18 @@ public class DetailActivity extends AppCompatActivity implements MainContract.It public void onFailureAnswer(int errorCode) { switch (errorCode) { case 1: { - Toast.makeText(DetailActivity.this, "Ошибка сети. Проверьте подключение к сети или данные подключения к API!", Toast.LENGTH_LONG).show(); - Log.e("DetailActivity", "Network Error! Re-check your connection credentials or network settings!"); + Toast.makeText(ItemActivity.this, "Ошибка сети. Проверьте подключение к сети или данные подключения к API!", Toast.LENGTH_LONG).show(); + Log.e("ItemActivity", "Network Error! Re-check your connection credentials or network settings!"); break; } case 2: { - Toast.makeText(DetailActivity.this, "Ответ от сервера неверен! Перепроверьте данные подключения!", Toast.LENGTH_LONG).show(); - Log.e("DetailActivity", "Answer of server is wrong! Re-check your connection credentials!"); + Toast.makeText(ItemActivity.this, "Ответ от сервера неверен! Перепроверьте данные подключения!", Toast.LENGTH_LONG).show(); + Log.e("ItemActivity", "Answer of server is wrong! Re-check your connection credentials!"); break; } case 3: { - Toast.makeText(DetailActivity.this, "Вы ввели неверный URL. Пример: http://example.ru", Toast.LENGTH_LONG).show(); - Log.e("DetailActivity", "Invalid-formatted URL. Please, check URL (change his if it need) and try again."); + Toast.makeText(ItemActivity.this, "Вы ввели неверный URL. Пример: http://example.ru", Toast.LENGTH_LONG).show(); + Log.e("ItemActivity", "Invalid-formatted URL. Please, check URL (change his if it need) and try again."); break; } } @@ -135,7 +150,7 @@ public class DetailActivity extends AppCompatActivity implements MainContract.It @Override public void setViewPagerContent(String[] uris) { - imagePagerAdapter = new ImagePagerAdapter(DetailActivity.this, uris); + imagePagerAdapter = new ImagePagerAdapter(ItemActivity.this, uris); TabLayout tabLayout = findViewById(R.id.tabDots); viewPager.setAdapter(imagePagerAdapter); setViewPagerScrollListener(); @@ -200,4 +215,34 @@ public class DetailActivity extends AppCompatActivity implements MainContract.It }; viewPager.setOnPageChangeListener(listener); } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.item_activity_menu, menu); + return true; + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + MenuItem addToFavorites = menu.findItem(R.id.action_favorite); + MenuItem deleteFromFavorites = menu.findItem(R.id.action_unfavorite); + + addToFavorites.setOnMenuItemClickListener((MenuItem menuItem) -> { + db.add(new FavoritesListModel(0, itemID, itemName)); + inFavorites = true; + this.invalidateOptionsMenu(); + return true; + }); + deleteFromFavorites.setOnMenuItemClickListener((MenuItem menuItem) -> { + db.removeItem(db.getFavoriteID(itemID)); + inFavorites = false; + this.invalidateOptionsMenu(); + return true; + }); + + addToFavorites.setVisible(!inFavorites); + deleteFromFavorites.setVisible(inFavorites); + return true; + } } diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/view/MainActivity.java b/app/src/main/java/ru/volgorobot/vrcatalog/view/MainActivity.java index 71a2ea2..12ec8bd 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/view/MainActivity.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/view/MainActivity.java @@ -113,6 +113,8 @@ public class MainActivity extends AppCompatActivity } else if (id == R.id.nav_about) { startActivity(new Intent(this, AboutActivity.class)); + } else if(id == R.id.nav_favorites) { + startActivity(new Intent(this, FavoritesActivity.class)); } DrawerLayout drawer = findViewById(R.id.drawer_layout); diff --git a/app/src/main/res/drawable/ic_favorite_black_24dp.xml b/app/src/main/res/drawable/ic_favorite_black_24dp.xml new file mode 100644 index 0000000..cfba5d8 --- /dev/null +++ b/app/src/main/res/drawable/ic_favorite_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_favorite_border_white_24dp.xml b/app/src/main/res/drawable/ic_favorite_border_white_24dp.xml new file mode 100644 index 0000000..63fb576 --- /dev/null +++ b/app/src/main/res/drawable/ic_favorite_border_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_favorite_white_24dp.xml b/app/src/main/res/drawable/ic_favorite_white_24dp.xml new file mode 100644 index 0000000..67a25e7 --- /dev/null +++ b/app/src/main/res/drawable/ic_favorite_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_favorites.xml b/app/src/main/res/layout/activity_favorites.xml new file mode 100644 index 0000000..14f501e --- /dev/null +++ b/app/src/main/res/layout/activity_favorites.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/activity_main_drawer.xml b/app/src/main/res/menu/activity_main_drawer.xml index 0bf6303..4bcd925 100644 --- a/app/src/main/res/menu/activity_main_drawer.xml +++ b/app/src/main/res/menu/activity_main_drawer.xml @@ -8,6 +8,10 @@ android:icon="@drawable/ic_home" android:title="Главная" android:checked="true" /> + - diff --git a/app/src/main/res/menu/item_activity_menu.xml b/app/src/main/res/menu/item_activity_menu.xml new file mode 100644 index 0000000..d97f786 --- /dev/null +++ b/app/src/main/res/menu/item_activity_menu.xml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file