Compare commits

...

9 Commits

Author SHA1 Message Date
ChronosX88
4f17ce2357
Merge remote-tracking branch 'origin/master' into develop 2019-02-27 18:47:45 +04:00
ChronosX88
c48ad1c2d9
Fixed app version 2019-02-27 18:43:54 +04:00
ChronosX88
60ebb68e76
Releasing 1.0.0 2019-02-27 18:04:50 +04:00
ChronosX88
d20de8da99
Migration to AndroidX and transfer of communication with the database from a low-level implementation to Room. 2019-02-27 18:02:42 +04:00
ChronosX88
7ed5e7dd9a
Fixed bug with zooming in viewpager (FullScreenActivity) (application crashed) 2019-02-25 18:54:36 +04:00
ChronosX88
e18caebad7
Merge remote-tracking branch 'origin/develop' 2019-02-24 18:50:04 +04:00
ChronosX88
44cb60762a
Releasing 0.4.0 2019-02-19 20:12:04 +04:00
ChronosX88
aed3cfb794
Merge remote-tracking branch 'origin/develop' 2019-02-16 19:44:03 +04:00
ChronosX88
b6200a39d9 Merge branch 'develop' into 'master'
Release version 0.3

See merge request ChronosX88/VRCatalog!5
2019-02-15 16:36:09 +00:00
35 changed files with 395 additions and 228 deletions

Binary file not shown.

View File

@ -2,6 +2,5 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,14 +1,18 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
compileSdkVersion 28
defaultConfig {
applicationId "ru.volgorobot.vrcatalog"
minSdkVersion 19
targetSdkVersion 27
versionCode 7
versionName "0.5.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
versionCode 8
versionName "1.0.0"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
@ -24,15 +28,19 @@ android {
}
dependencies {
def room_version = "2.1.0-alpha04"
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'me.texy.treeview:treeview_lib:1.0.4'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.github.chrisbanes:PhotoView:2.1.4'
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
}

View File

@ -0,0 +1,46 @@
{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "b484b5731c959dea19f42d92a1fccfcd",
"entities": [
{
"tableName": "favorites",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `itemID` INTEGER NOT NULL, `itemName` TEXT)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "itemID",
"columnName": "itemID",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "itemName",
"columnName": "itemName",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"b484b5731c959dea19f42d92a1fccfcd\")"
]
}
}

View File

@ -0,0 +1,46 @@
{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "b484b5731c959dea19f42d92a1fccfcd",
"entities": [
{
"tableName": "favorites",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `itemID` INTEGER NOT NULL, `itemName` TEXT)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "itemID",
"columnName": "itemID",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "itemName",
"columnName": "itemName",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"b484b5731c959dea19f42d92a1fccfcd\")"
]
}
}

View File

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="ru.volgorobot.vrcatalog">
<uses-permission android:name="android.permission.INTERNET" />
@ -10,7 +12,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:name=".App">
<activity android:name=".view.FavoritesActivity"></activity>
<activity
android:name=".view.MainActivity"

View File

@ -0,0 +1,25 @@
package ru.volgorobot.vrcatalog;
import android.app.Application;
import android.content.Context;
import androidx.room.Room;
import ru.volgorobot.vrcatalog.additional.DatabaseHelper;
public class App extends Application {
private static Application instance;
private static DatabaseHelper db;
@Override
public void onCreate() {
super.onCreate();
instance = this;
db = Room.databaseBuilder(getApplicationContext(), DatabaseHelper.class, "mainDatabase")
.allowMainThreadQueries()
.build();
}
public static Context getContext() { return instance.getApplicationContext(); }
public static DatabaseHelper getDatabaseInstance() { return db; }
}

View File

@ -6,8 +6,10 @@ import java.util.ArrayList;
import me.texy.treeview.TreeNode;
import ru.volgorobot.vrcatalog.additional.NetworkErrorException;
import ru.volgorobot.vrcatalog.additional.adapters.FavoritesListAdapter;
import ru.volgorobot.vrcatalog.model.CoreModel;
import ru.volgorobot.vrcatalog.model.DetailModel;
import ru.volgorobot.vrcatalog.model.FavoritesModel;
import ru.volgorobot.vrcatalog.model.FirstLevelModel;
import ru.volgorobot.vrcatalog.model.ImageItemModel;
import ru.volgorobot.vrcatalog.model.SecondLevelModel;
@ -34,12 +36,15 @@ public interface MainContract {
}
interface FavoritesPresenter {
void getAllItems();
void removeItem(int id);
void fetchItem(int itemID);
}
interface FavoritesActivityView {
void onFailruleAnswer(int errorCode);
void onFailureAnswer(int errorCode);
void startActivityByIntent(Intent intent);
void updateListView(ArrayList<FavoritesModel> data);
}
interface ViewBinder {
@ -71,6 +76,10 @@ public interface MainContract {
interface ItemPresenter {
void getImagesByItemID(int id);
boolean checkFavoriteListed(int itemID);
int getFavoriteID(int itemID);
void addToFavorites(int itemID, String itemName);
void removeFromFavorites(int favID);
}
interface ItemView {

View File

@ -17,11 +17,11 @@ package ru.volgorobot.vrcatalog.additional;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;

View File

@ -0,0 +1,11 @@
package ru.volgorobot.vrcatalog.additional;
import androidx.room.Database;
import androidx.room.RoomDatabase;
import ru.volgorobot.vrcatalog.model.FavoritesDaoModel;
import ru.volgorobot.vrcatalog.model.FavoritesModel;
@Database(entities = {FavoritesModel.class}, version = 1)
public abstract class DatabaseHelper extends RoomDatabase {
public abstract FavoritesDaoModel getFavoritesDaoModel();
}

View File

@ -0,0 +1,42 @@
package ru.volgorobot.vrcatalog.additional;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import androidx.viewpager.widget.ViewPager;
/**
* ViewPager fixer class (which fix bug with zooming)
*/
public class HackyViewPager extends ViewPager {
public HackyViewPager(Context context) {
super(context);
}
public HackyViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
try {
return super.onTouchEvent(ev);
} catch (IllegalArgumentException ex) {
ex.printStackTrace();
}
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
return super.onInterceptTouchEvent(ev);
} catch (IllegalArgumentException ex) {
ex.printStackTrace();
}
return false;
}
}

View File

@ -3,25 +3,22 @@ package ru.volgorobot.vrcatalog.additional.adapters;
import android.content.Context;
import android.widget.ArrayAdapter;
import java.util.ArrayList;
import java.util.List;
import ru.volgorobot.vrcatalog.model.FavoritesListModel;
import ru.volgorobot.vrcatalog.presenters.FavoritesDBPresenter;
import ru.volgorobot.vrcatalog.model.FavoritesModel;
public class FavoritesListAdapter extends ArrayAdapter<FavoritesListModel> {
private FavoritesDBPresenter db;
public FavoritesListAdapter(Context context, int resource, List<FavoritesListModel> objects) {
public class FavoritesListAdapter extends ArrayAdapter<FavoritesModel> {
public FavoritesListAdapter(Context context, int resource, List<FavoritesModel> objects) {
super(context, resource, objects);
db = new FavoritesDBPresenter(context);
}
public void updateData() {
public void updateData(ArrayList<FavoritesModel> data) {
super.clear();
super.addAll(db.selectAll());
super.addAll(data);
}
public int getArraySize() {
return db.selectAll().size();
return super.getCount();
}
}

View File

@ -1,9 +1,9 @@
package ru.volgorobot.vrcatalog.additional.adapters;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.support.v7.widget.Toolbar;
import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;

View File

@ -5,8 +5,8 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

View File

@ -0,0 +1,22 @@
package ru.volgorobot.vrcatalog.model;
import java.util.List;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
@Dao
public interface FavoritesDaoModel {
@Query("SELECT * FROM favorites")
List<FavoritesModel> getAll();
@Query("SELECT * FROM favorites WHERE itemID = :itemID")
List<FavoritesModel> getFavoriteByItemID(int itemID);
@Insert
void add(FavoritesModel model);
@Query("DELETE FROM favorites WHERE id = :id")
void remove(int id);
}

View File

@ -1,17 +1,21 @@
package ru.volgorobot.vrcatalog.model;
public class FavoritesListModel {
private int id;
private int itemID;
private String itemName;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
public FavoritesListModel(int itemID, String itemName) {
this.itemID = itemID;
this.itemName = itemName;
}
@Entity(tableName = "favorites")
public class FavoritesModel {
@PrimaryKey(autoGenerate = true)
public int id;
public FavoritesListModel(int id, int itemID, String itemName) {
this.id = id;
@ColumnInfo
public int itemID;
@ColumnInfo
public String itemName;
public FavoritesModel(int itemID, String itemName) {
this.itemID = itemID;
this.itemName = itemName;
}

View File

@ -1,11 +1,8 @@
package ru.volgorobot.vrcatalog.nodeViewBinders;
import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import me.texy.treeview.TreeNode;

View File

@ -1,83 +0,0 @@
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<FavoritesListModel> selectAll() {
ArrayList<FavoritesListModel> 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;
}
}

View File

@ -1,16 +1,21 @@
package ru.volgorobot.vrcatalog.presenters;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import java.util.ArrayList;
import androidx.room.Room;
import ru.volgorobot.vrcatalog.App;
import ru.volgorobot.vrcatalog.MainContract;
import ru.volgorobot.vrcatalog.additional.DatabaseHelper;
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.model.FavoritesModel;
import ru.volgorobot.vrcatalog.view.FavoritesActivity;
import ru.volgorobot.vrcatalog.view.ItemActivity;
@ -18,13 +23,16 @@ public class FavoritesPresenter implements MainContract.FavoritesPresenter {
private Context mContext;
private MainContract.MainModel mainModel;
private MainContract.FavoritesActivityView mView;
private DatabaseHelper db;
public FavoritesPresenter(Context context, FavoritesActivity view) {
this.mContext = context;
this.mainModel = new CoreModel(context);
public FavoritesPresenter(FavoritesActivity view) {
this.mContext = App.getContext();
this.mainModel = new CoreModel(mContext);
this.mView = view;
this.db = App.getDatabaseInstance();
}
@SuppressLint("StaticFieldLeak")
@Override
public void fetchItem(int itemID) {
new AsyncTask<Integer, Void, ResultWithErrorCode<DetailModel>>() {
@ -59,19 +67,30 @@ public class FavoritesPresenter implements MainContract.FavoritesPresenter {
break;
}
case 1: {
mView.onFailruleAnswer(1);
mView.onFailureAnswer(1);
break;
}
case 2: {
mView.onFailruleAnswer(2);
mView.onFailureAnswer(2);
break;
}
case 3: {
mView.onFailruleAnswer(3);
mView.onFailureAnswer(3);
break;
}
}
}
}.execute(itemID);
}
@Override
public void getAllItems() {
mView.updateListView((ArrayList<FavoritesModel>) db.getFavoritesDaoModel().getAll());
}
@Override
public void removeItem(int id) {
db.getFavoritesDaoModel().remove(id);
mView.updateListView((ArrayList<FavoritesModel>) db.getFavoritesDaoModel().getAll());
}
}

View File

@ -15,21 +15,27 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.UUID;
import androidx.room.Room;
import ru.volgorobot.vrcatalog.App;
import ru.volgorobot.vrcatalog.MainContract;
import ru.volgorobot.vrcatalog.additional.DatabaseHelper;
import ru.volgorobot.vrcatalog.additional.NetworkErrorException;
import ru.volgorobot.vrcatalog.additional.ResultWithErrorCode;
import ru.volgorobot.vrcatalog.model.CoreModel;
import ru.volgorobot.vrcatalog.model.FavoritesModel;
import ru.volgorobot.vrcatalog.model.ImageItemModel;
public class ItemPresenter implements MainContract.ItemPresenter {
private MainContract.ItemView mView;
private Context context;
private MainContract.MainModel coreModel;
private DatabaseHelper db;
public ItemPresenter(Context context, MainContract.ItemView itemView) {
public ItemPresenter(MainContract.ItemView itemView) {
this.mView = itemView;
this.context = context;
this.context = App.getContext();
this.coreModel = new CoreModel(context);
this.db = App.getDatabaseInstance();
}
@SuppressLint("StaticFieldLeak")
@ -101,4 +107,27 @@ public class ItemPresenter implements MainContract.ItemPresenter {
}
return Uri.fromFile(cacheObject);
}
@Override
public boolean checkFavoriteListed(int itemID) {
return db.getFavoritesDaoModel().getFavoriteByItemID(itemID).size() != 0;
}
@Override
public int getFavoriteID(int itemID) {
ArrayList<FavoritesModel> models = (ArrayList<FavoritesModel>) db.getFavoritesDaoModel().getFavoriteByItemID(itemID);
if(models.size() != 0)
return models.get(0).getID();
return 0;
}
@Override
public void addToFavorites(int itemID, String itemName) {
db.getFavoritesDaoModel().add(new FavoritesModel(itemID, itemName));
}
@Override
public void removeFromFavorites(int favID) {
db.getFavoritesDaoModel().remove(favID);
}
}

View File

@ -1,7 +1,7 @@
package ru.volgorobot.vrcatalog.view;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;
import android.view.MenuItem;
import ru.volgorobot.vrcatalog.R;

View File

@ -1,8 +1,8 @@
package ru.volgorobot.vrcatalog.view;
import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
@ -19,12 +19,10 @@ 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.model.FavoritesModel;
import ru.volgorobot.vrcatalog.presenters.FavoritesPresenter;
public class FavoritesActivity extends AppCompatActivity implements MainContract.FavoritesActivityView {
private FavoritesDBPresenter db;
private FavoritesListAdapter adapter;
private MainContract.FavoritesPresenter mPresenter;
@ -37,15 +35,13 @@ public class FavoritesActivity extends AppCompatActivity implements MainContract
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_favorites);
mPresenter = new FavoritesPresenter(FavoritesActivity.this, this);
mPresenter = new FavoritesPresenter(this);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setTitle("Избранное");
db = new FavoritesDBPresenter(FavoritesActivity.this);
initViews();
}
@ -55,16 +51,14 @@ public class FavoritesActivity extends AppCompatActivity implements MainContract
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
FavoritesListModel model = (FavoritesListModel) listView.getItemAtPosition(i);
FavoritesModel model = (FavoritesModel) listView.getItemAtPosition(i);
mPresenter.fetchItem(model.getItemID());
}
});
adapter = new FavoritesListAdapter(FavoritesActivity.this, android.R.layout.simple_list_item_1, new ArrayList<>());
listView.setAdapter(adapter);
favoritesEmptyImage = findViewById(R.id.favorites_empty_image);
favoritesEmptyText = findViewById(R.id.favorites_empty_text);
ArrayList<FavoritesListModel> models = db.selectAll();
adapter = new FavoritesListAdapter(FavoritesActivity.this, android.R.layout.simple_list_item_1, models);
listView.setAdapter(adapter);
checkForEmptyContent();
}
public void checkForEmptyContent() {
@ -84,18 +78,18 @@ public class FavoritesActivity extends AppCompatActivity implements MainContract
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case 0: {
FavoritesListModel model = (FavoritesListModel) listView.getItemAtPosition(info.position);
db.removeItem(model.getID());
updateListView();
checkForEmptyContent();
FavoritesModel model = (FavoritesModel) listView.getItemAtPosition(info.position);
mPresenter.removeItem(model.getID());
}
}
return true;
}
private void updateListView() {
adapter.updateData();
@Override
public void updateListView(ArrayList<FavoritesModel> data) {
adapter.updateData(data);
adapter.notifyDataSetChanged();
checkForEmptyContent();
}
@Override
@ -116,7 +110,7 @@ public class FavoritesActivity extends AppCompatActivity implements MainContract
}
@Override
public void onFailruleAnswer(int errorCode) {
public void onFailureAnswer(int errorCode) {
switch (errorCode) {
case 1: {
Toast.makeText(FavoritesActivity.this, "Ошибка сети. Проверьте подключение к сети или данные подключения к API!", Toast.LENGTH_LONG).show();
@ -144,7 +138,6 @@ public class FavoritesActivity extends AppCompatActivity implements MainContract
@Override
protected void onResume() {
super.onResume();
updateListView();
checkForEmptyContent();
mPresenter.getAllItems();
}
}

View File

@ -4,11 +4,11 @@ import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;

View File

@ -4,10 +4,11 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import com.google.android.material.tabs.TabLayout;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
@ -17,10 +18,7 @@ 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;
@ -33,9 +31,9 @@ public class ItemActivity extends AppCompatActivity implements MainContract.Item
private ListView propertiesList;
private ImagePagerAdapter imagePagerAdapter;
private boolean inFavorites;
private FavoritesDBPresenter db;
private int itemID;
private String itemName;
private int favoriteID;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -47,7 +45,7 @@ public class ItemActivity extends AppCompatActivity implements MainContract.Item
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
initializeViews();
mPresenter = new ItemPresenter(ItemActivity.this, this);
mPresenter = new ItemPresenter(this);
Intent intent = getIntent();
itemName = intent.getStringExtra("detailName");
@ -63,7 +61,6 @@ public class ItemActivity extends AppCompatActivity implements MainContract.Item
LinkedHashMap<String, String> 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(intentDataForListView);
@ -71,7 +68,8 @@ public class ItemActivity extends AppCompatActivity implements MainContract.Item
mPresenter.getImagesByItemID(Integer.parseInt(intent.getStringExtra("itemID")));
inFavorites = db.inFavoritesList(itemID);
inFavorites = mPresenter.checkFavoriteListed(itemID);
favoriteID = mPresenter.getFavoriteID(itemID);
}
void initializeViews() {
@ -229,13 +227,13 @@ public class ItemActivity extends AppCompatActivity implements MainContract.Item
MenuItem deleteFromFavorites = menu.findItem(R.id.action_unfavorite);
addToFavorites.setOnMenuItemClickListener((MenuItem menuItem) -> {
db.add(new FavoritesListModel(0, itemID, itemName));
mPresenter.addToFavorites(itemID, itemName);
inFavorites = true;
this.invalidateOptionsMenu();
return true;
});
deleteFromFavorites.setOnMenuItemClickListener((MenuItem menuItem) -> {
db.removeItem(db.getFavoriteID(itemID));
mPresenter.removeFromFavorites(favoriteID);
inFavorites = false;
this.invalidateOptionsMenu();
return true;

View File

@ -5,16 +5,15 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.core.view.GravityCompat;
import androidx.core.view.MenuItemCompat;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
@ -25,6 +24,8 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.material.navigation.NavigationView;
import java.util.ArrayList;
import me.texy.treeview.TreeNode;

View File

@ -4,14 +4,13 @@ import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.provider.SearchRecentSuggestions;
import android.support.v4.widget.NestedScrollView;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import androidx.core.widget.NestedScrollView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DefaultItemAnimator;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

View File

@ -1,25 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways">
<android.support.v4.view.ViewPager
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_width="wrap_content"
android:layout_height="311dp"
app:layout_collapseMode="parallax" />
<android.support.design.widget.TabLayout
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabDots"
android:layout_width="match_parent"
android:layout_height="62dp"
@ -27,7 +27,7 @@
app:tabBackground="@drawable/tab_selector"
app:tabGravity="center"
app:tabIndicatorHeight="0dp" />
<android.support.v7.widget.Toolbar
<androidx.appcompat.widget.Toolbar
android:id="@+id/itemactivity_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
@ -35,10 +35,10 @@
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:theme="@style/ItemActionBar"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<android.support.v4.widget.NestedScrollView
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="619dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
@ -74,5 +74,5 @@
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:nestedScrollingEnabled="false"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linearLayout"
@ -44,4 +44,4 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/favorites_empty_image" />
</android.support.constraint.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -9,12 +9,12 @@
tools:context="ru.volgorobot.vrcatalog.view.FullScreenImageActivity"
android:background="@android:color/black">
<android.support.v4.view.ViewPager
<ru.volgorobot.vrcatalog.additional.HackyViewPager
android:id="@+id/fullscreen_mode_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.v7.widget.Toolbar
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
@ -13,7 +13,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
@ -22,4 +22,4 @@
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
</androidx.drawerlayout.widget.DrawerLayout>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@ -10,16 +10,16 @@
android:orientation="horizontal"
android:id="@+id/searchableSwipeRefreshLayout">
<android.support.constraint.ConstraintLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
<androidx.core.widget.NestedScrollView
android:id="@+id/searchableTreeViewContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarAlwaysDrawVerticalTrack="true">
</android.support.v4.widget.NestedScrollView>
</androidx.core.widget.NestedScrollView>
<ImageView
android:id="@+id/searchableConnectionErrorImageView"
@ -80,6 +80,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/emptySearchImage" />
</android.support.constraint.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.MainActivity">
<android.support.design.widget.AppBarLayout
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
@ -20,8 +20,8 @@
app:titleTextColor="@android:color/white"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@ -10,12 +10,12 @@
android:orientation="horizontal"
android:id="@+id/swipeRefreshLayout">
<android.support.constraint.ConstraintLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/mainActivityConstraint"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
<androidx.core.widget.NestedScrollView
android:id="@+id/treeViewContainer"
android:layout_width="0dp"
android:layout_height="0dp"
@ -27,7 +27,7 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0">
</android.support.v4.widget.NestedScrollView>
</androidx.core.widget.NestedScrollView>
<ImageView
android:id="@+id/connectionErrorImageView"
@ -59,6 +59,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/connectionErrorImageView" />
</android.support.constraint.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

View File

@ -5,6 +5,6 @@
android:id="@+id/action_search"
android:icon="@drawable/ic_search_white_24dp"
app:showAsAction="always|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView"
app:actionViewClass="androidx.appcompat.widget.SearchView"
android:title="Поиск"/>
</menu>

View File

@ -6,6 +6,8 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx512m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit