Skip to content

Commit

Permalink
Version 1.0.1 (#1)
Browse files Browse the repository at this point in the history
* workaround for cdn caching sitemaps; compact OSS licenses list; version update

* custom OSS adapter; Triple-T directory structure

* pump images cache to 64 Mb
  • Loading branch information
anegrin authored Jan 5, 2020
1 parent f13a216 commit de0b25d
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "io.github.chiver"
minSdkVersion 24
targetSdkVersion 28
versionCode 100
versionName "1.0.0"
versionCode 101
versionName "1.0.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/io/github/chiver/Chiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Chiver() {
public void onCreate() {
super.onCreate();
try {
simpleDiskCache = SimpleDiskCache.open(getExternalCacheDir(), 1, 32 * 1024 * 1024);
simpleDiskCache = SimpleDiskCache.open(getExternalCacheDir(), 1, 64 * 1024 * 1024);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/io/github/chiver/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class Constants {
private static final String TC = "thechive";
private static final String TC_BASE_URL = "https://" + TC + ".com/";
static final String TC_SITEMAP_PATTERN = TC_BASE_URL + "sitemap.xml?yyyy=%d&mm=%d&dd=%d";
static final String TC_SITEMAP_PATTERN = TC_BASE_URL + "sitemap.xml?yyyy=%d&mm=%d&dd=%d&_rnd=%s";
public static final String TAG = Chiver.class.getSimpleName();

private Constants() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/io/github/chiver/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void loadGalleries() {
int month = utc.get(Calendar.MONTH) + 1;//0 based
int day = utc.get(Calendar.DAY_OF_MONTH);

StringRequest stringRequest = new StringRequest(String.format(Locale.getDefault(), Constants.TC_SITEMAP_PATTERN, year, month, day), response -> {
StringRequest stringRequest = new StringRequest(String.format(Locale.getDefault(), Constants.TC_SITEMAP_PATTERN, year, month, day, String.valueOf(Math.random())), response -> {

SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
try {
Expand Down
28 changes: 20 additions & 8 deletions app/src/main/java/io/github/chiver/OSSActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import io.github.chiver.adapter.LicenseAdapter;

public class OSSActivity extends BaseActivity {

private final List<String> items = new LinkedList<>();
private final List<String> links = new LinkedList<>();
private final Map<String, List<String>> linksToItems = new HashMap<>();

public OSSActivity() {
super(false);
Expand All @@ -32,6 +35,9 @@ protected void _onCreate(Bundle savedInstanceState) {
getSupportActionBar().setTitle(R.string.oss_licenses);
ListView lvLicenses = findViewById(R.id.lv_licenses);

final List<String> links = new LinkedList<>();
final List<String> items = new LinkedList<>();

try (InputStream is = getResources().openRawResource(R.raw.third_party_license_metadata);
InputStreamReader isr = new InputStreamReader(is);
BufferedReader reader = new BufferedReader(isr)) {
Expand All @@ -52,8 +58,15 @@ protected void _onCreate(Bundle savedInstanceState) {
onLoadingError();
}

ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, items);
for (Iterator<String> itemsIterator = items.iterator(), linksIterator = links.iterator(); itemsIterator.hasNext() && linksIterator.hasNext(); ) {
String item = itemsIterator.next();
String link = linksIterator.next();

List<String> itemsList = linksToItems.computeIfAbsent(link, k -> new LinkedList<>());
itemsList.add(item);
}

LicenseAdapter adapter = new LicenseAdapter(this, linksToItems);

lvLicenses.setAdapter(adapter);

Expand All @@ -62,13 +75,12 @@ protected void _onCreate(Bundle savedInstanceState) {

private void onLoadingError() {
Toast.makeText(this, R.string.loadingError, Toast.LENGTH_SHORT).show();
items.clear();
links.clear();
linksToItems.clear();
}

@SuppressWarnings("unused")
private void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
String link = links.get(position);
String link = adapterView.getAdapter().getItem(position).toString();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link)));
}

Expand Down
40 changes: 40 additions & 0 deletions app/src/main/java/io/github/chiver/adapter/LicenseAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.github.chiver.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class LicenseAdapter extends ArrayAdapter<String> {

private final Map<String, List<String>> linksToItems;

public LicenseAdapter(@NonNull Context context, Map<String, List<String>> linksToItems) {
super(context, android.R.layout.simple_list_item_2, android.R.id.text1, new ArrayList<>(linksToItems.keySet()));
this.linksToItems = linksToItems;
}

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View view = super.getView(position, convertView, parent);

String link = getItem(position);

TextView text2 = view.findViewById(android.R.id.text2);
//noinspection ConstantConditions,SimplifyStreamApiCallChains
text2.setText(linksToItems.getOrDefault(link, Collections.emptyList()).stream().collect(Collectors.joining(", ")));

return view;
}
}
1 change: 1 addition & 0 deletions app/src/main/play/default-language.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
en-US
3 changes: 3 additions & 0 deletions app/src/main/play/listings/en-US/full-description.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Chiver is a minimalistic theCHIVE galleries browser.

The app can display images and animated GIFs; it does not display videos (but you can open the gallery in external browser).
File renamed without changes
1 change: 1 addition & 0 deletions app/src/main/play/listings/en-US/short-description.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Minimalistic theCHIVE galleries browser
1 change: 1 addition & 0 deletions app/src/main/play/listings/en-US/title.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Chiver

0 comments on commit de0b25d

Please sign in to comment.