Skip to content

Commit

Permalink
Version 1.1.1 (#7)
Browse files Browse the repository at this point in the history
* next new version: 1.1.1; dev build type with different name and icons

* refresh gesture on main activity

* next and prev tap on view pager + fade out animation
  • Loading branch information
anegrin authored Jan 23, 2021
1 parent 1214d8f commit c335db7
Show file tree
Hide file tree
Showing 23 changed files with 221 additions and 37 deletions.
10 changes: 8 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ android {
applicationId "io.github.chiver"
minSdkVersion 24
targetSdkVersion 28
versionCode 110
versionName "1.1.0"
versionCode 111
versionName "1.1.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
dev {
applicationIdSuffix ".dev"
debuggable true
signingConfig signingConfigs.debug
}
}
compileOptions {
sourceCompatibility = 1.8
Expand All @@ -27,6 +32,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand Down
Binary file added app/src/dev/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions app/src/dev/res/drawable/ic_launcher_foreground.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108"
android:tint="#FFFFFF">
<group android:scaleX="3.437561"
android:scaleY="3.437561"
android:translateX="12.749269"
android:translateY="12.749269">
<path
android:fillColor="@android:color/white"
android:pathData="M20,8h-2.81c-0.45,-0.78 -1.07,-1.45 -1.82,-1.96L17,4.41 15.59,3l-2.17,2.17C12.96,5.06 12.49,5 12,5c-0.49,0 -0.96,0.06 -1.41,0.17L8.41,3 7,4.41l1.62,1.63C7.88,6.55 7.26,7.22 6.81,8L4,8v2h2.09c-0.05,0.33 -0.09,0.66 -0.09,1v1L4,12v2h2v1c0,0.34 0.04,0.67 0.09,1L4,16v2h2.81c1.04,1.79 2.97,3 5.19,3s4.15,-1.21 5.19,-3L20,18v-2h-2.09c0.05,-0.33 0.09,-0.66 0.09,-1v-1h2v-2h-2v-1c0,-0.34 -0.04,-0.67 -0.09,-1L20,10L20,8zM14,16h-4v-2h4v2zM14,12h-4v-2h4v2z"/>
</group>
</vector>
5 changes: 5 additions & 0 deletions app/src/dev/res/mipmap-anydpi-v26/ic_launcher.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>
5 changes: 5 additions & 0 deletions app/src/dev/res/mipmap-anydpi-v26/ic_launcher_round.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>
Binary file added app/src/dev/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/dev/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/dev/res/mipmap-mdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/dev/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/dev/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/dev/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/src/dev/res/values/ic_launcher_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#00C300</color>
</resources>
3 changes: 3 additions & 0 deletions app/src/dev/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">Chiver - dev</string>
</resources>
80 changes: 76 additions & 4 deletions app/src/main/java/io/github/chiver/ItemActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;

import androidx.annotation.NonNull;
import androidx.core.app.ShareCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;

import io.github.chiver.util.CachingImageLoader;

public class ItemActivity extends BaseActivity {
Expand All @@ -26,6 +30,8 @@ public class ItemActivity extends BaseActivity {
private ImageLoader imageLoader;
private ViewPager vpItem;
private String[] urls;
private View ivPrev;
private View ivNext;

public ItemActivity() {
super(false);
Expand All @@ -41,6 +47,72 @@ protected void _onCreate(Bundle savedInstanceState) {
vpItem.setCurrentItem(pos);
vpItem.addOnPageChangeListener(new DisplayPage(findViewById(R.id.tv_pages), urls.length));

View llPrev = findViewById(R.id.ll_prev);
llPrev.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int currentItem = vpItem.getCurrentItem();
boolean hasPrev = currentItem > 0;
if (hasPrev) {
vpItem.setCurrentItem(currentItem - 1);
}
}
});

View llNext = findViewById(R.id.ll_next);
llNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int currentItem = vpItem.getCurrentItem();
boolean hasNext = currentItem < urls.length - 1;
if (hasNext) {
vpItem.setCurrentItem(currentItem + 1);
}
}
});

ivPrev = findViewById(R.id.iv_prev);
ivNext = findViewById(R.id.iv_next);

if (pos == 0) {
ivPrev.setVisibility(View.INVISIBLE);
} else if (pos == urls.length - 1) {
ivNext.setVisibility(View.INVISIBLE);
}
}

@Override
protected void onResume() {
super.onResume();
fadeOut(ivPrev);
fadeOut(ivNext);
}

private void fadeOut(View view) {

if (view.getVisibility() == View.VISIBLE) {

Animation animation = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);
animation.setDuration(1000);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationEnd(Animation animation) {
view.setVisibility(View.INVISIBLE);
}

@Override
public void onAnimationRepeat(Animation animation) {

}
});

view.startAnimation(animation);
}
}

@Override
Expand Down
63 changes: 48 additions & 15 deletions app/src/main/java/io/github/chiver/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.StringRequest;
Expand All @@ -35,6 +36,7 @@ public class MainActivity extends BaseActivity {
private RequestQueue requestQueue;
private int page = 1;
private ProgressDialog progressDialog;
private SwipeRefreshLayout swipeRefreshLayout;


@Override
Expand All @@ -46,7 +48,7 @@ protected void _onCreate(Bundle savedInstanceState) {
recyclerView.setHasFixedSize(true);
adapter = new GalleryAdapter(this, getChiver().getSimpleDiskCache());
recyclerView.setAdapter(adapter);
loadGalleries();
loadGalleries(false);

GridLayoutManager layoutManager = (GridLayoutManager) recyclerView.getLayoutManager();

Expand All @@ -59,12 +61,20 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
if (layoutManager != null) {
boolean canScroll = layoutManager.findLastCompletelyVisibleItemPosition() < adapter.getItemCount() - 1;
if (!canScroll) {
loadGalleries();
loadGalleries(false);
}
}

}
});

swipeRefreshLayout = findViewById(R.id.srl_gallery_items);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
doRefresh();
}
});
}

@Override
Expand All @@ -79,32 +89,32 @@ protected int getContentView() {
return R.layout.activity_main;
}

private void loadGalleries() {
private void loadGalleries(boolean refresh) {

progressDialog.show();
onStartLoading(refresh);

String url = page == 1 ? Constants.TC_MAIN_FEED : String.format(Locale.getDefault(), Constants.TC_FEED_PATTERN, page);
StringRequest stringRequest = new StringRequest(url, response -> {
parseAndNotifyProgress(response, progressDialog);
parseAndNotifyProgress(response, refresh);
}, error -> {

if (error.networkResponse != null && error.networkResponse.statusCode == 404) {

//sometimes we get 404 but even if we get proper response
if (isValidResponse(error.networkResponse.data)) {
String response = new String(error.networkResponse.data);
parseAndNotifyProgress(response, progressDialog);
parseAndNotifyProgress(response, refresh);
} else {
page++;
progressDialog.dismiss();
onEndLoading(refresh);
Toast.makeText(MainActivity.this, R.string.tryNextPage, Toast.LENGTH_SHORT).show();
loadGalleries();
loadGalleries(false);
}
return;
}

Log.e("Volley", error.toString());
progressDialog.dismiss();
onEndLoading(refresh);
Toast.makeText(MainActivity.this, R.string.loadingError, Toast.LENGTH_SHORT).show();
});
getRequestQueue().add(stringRequest);
Expand All @@ -121,22 +131,42 @@ private boolean isValidResponse(byte[] data) {
&& data[4] == 'l';
}

private void parseAndNotifyProgress(String response, ProgressDialog progressDialog) {
private void parseAndNotifyProgress(String response, boolean refresh) {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
try {
SAXParser saxParser = saxParserFactory.newSAXParser();
FeedSAXParser handler = new FeedSAXParser(adapter::addItem);
saxParser.parse(new InputSource(new StringReader(response)), handler);
} catch (ParserConfigurationException | SAXException | IOException e) {
Log.e("Volley", e.getMessage(), e);
progressDialog.dismiss();
onEndLoading(refresh);
Toast.makeText(MainActivity.this, R.string.loadingError, Toast.LENGTH_SHORT).show();
}

page++;

adapter.notifyDataSetChanged();
progressDialog.dismiss();
onEndLoading(refresh);
}

private void onStartLoading(boolean refresh) {
if (refresh) {
swipeRefreshLayout.setRefreshing(true);
} else {
progressDialog.show();
}
}

private void onEndLoading(boolean refresh) {
if (refresh) {
if (swipeRefreshLayout.isRefreshing()) {
swipeRefreshLayout.setRefreshing(false);
}
} else {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
}

private synchronized RequestQueue getRequestQueue() {
Expand All @@ -150,11 +180,14 @@ private synchronized RequestQueue getRequestQueue() {

@Override
protected boolean onRefresh(MenuItem item) {
doRefresh();
return super.onRefresh(item);
}

private void doRefresh() {
adapter.clearItems();
resetDaysCounter();
adapter.notifyDataSetChanged();
loadGalleries();
return super.onRefresh(item);
loadGalleries(true);
}

private void resetDaysCounter() {
Expand Down
44 changes: 40 additions & 4 deletions app/src/main/res/layout/activity_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical"
tools:context=".MainActivity"
android:background="@android:color/white">
tools:context=".MainActivity">

<include layout="@layout/toolbar" />

Expand All @@ -15,6 +15,42 @@
android:layout_height="match_parent"
android:layout_below="@+id/toolbar" />

<LinearLayout
android:id="@+id/ll_next"
android:layout_width="?attr/actionBarSize"
android:layout_height="match_parent"
android:layout_alignTop="@id/vp_item"
android:layout_alignBottom="@id/vp_item"
android:layout_alignParentEnd="true"
android:background="@android:color/transparent"
android:gravity="center"
android:orientation="horizontal">

<ImageView
android:id="@+id/iv_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_media_next" />
</LinearLayout>

<LinearLayout
android:id="@+id/ll_prev"
android:layout_width="?attr/actionBarSize"
android:layout_height="match_parent"
android:layout_alignTop="@id/vp_item"
android:layout_alignBottom="@id/vp_item"
android:layout_alignParentStart="false"
android:background="@android:color/transparent"
android:gravity="center"
android:orientation="horizontal">

<ImageView
android:id="@+id/iv_prev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_media_previous" />
</LinearLayout>

<TextView
android:id="@+id/tv_pages"
android:layout_width="match_parent"
Expand All @@ -25,7 +61,7 @@
android:shadowDx="2"
android:shadowDy="2"
android:shadowRadius="1.5"
android:textAllCaps="true"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="@android:color/white" />
</RelativeLayout>
</RelativeLayout>
Loading

0 comments on commit c335db7

Please sign in to comment.