Skip to content

Commit

Permalink
Merge pull request #43 from cutmail/develop
Browse files Browse the repository at this point in the history
Release 2018-08-08 15:22:11 +0900
  • Loading branch information
cutmail authored Feb 20, 2019
2 parents bfa85a4 + 65c5c81 commit b72aa62
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 69 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ out/

local.properties
.envrc
releasekey.keystore

# Eclipse project files
.classpath
Expand Down
37 changes: 19 additions & 18 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@ buildscript {
}

dependencies {
classpath 'io.fabric.tools:gradle:1.21.6'
classpath 'io.fabric.tools:gradle:1.27.1'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://maven.google.com' }
}

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
applicationId "me.cutmail.disasterapp"
minSdkVersion 14
targetSdkVersion 25
versionCode 17
versionName "1.7.0"
minSdkVersion 26
targetSdkVersion 28
versionCode 18
versionName "1.8.0"
}
buildTypes {
release {
Expand All @@ -34,18 +35,18 @@ android {
}

dependencies {
compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') {
transitive = true;
implementation('com.crashlytics.sdk.android:crashlytics:2.9.9@aar') {
transitive = true
}
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.jakewharton.timber:timber:4.5.1'
compile 'com.github.hotchemi:android-rate:1.0.1'
compile 'com.firebaseui:firebase-ui-database:0.6.1'
compile 'com.google.firebase:firebase-database:10.0.1'
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-crash:10.0.1'
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
implementation 'androidx.paging:paging-runtime:2.1.0'
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'com.github.hotchemi:android-rate:1.0.1'
implementation 'com.firebaseui:firebase-ui-firestore:4.3.1'
implementation 'com.google.firebase:firebase-database:16.0.6'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
}

apply plugin: 'com.google.gms.google-services'
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity
android:name=".activity.MainActivity"
android:label="@string/app_name">
Expand All @@ -34,6 +35,7 @@
<activity
android:name=".activity.AboutActivity"
android:label="@string/title_activity_about" />
<meta-data android:name="google_analytics_adid_collection_enabled" android:value="false" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import android.util.Log;

import com.crashlytics.android.Crashlytics;
import com.google.firebase.crash.FirebaseCrash;
import com.google.firebase.database.FirebaseDatabase;

import androidx.annotation.NonNull;
import timber.log.Timber;

public class DisasterApplication extends Application {
Expand All @@ -30,7 +30,7 @@ private void setupTimber() {
private static class CrashReportingTree extends Timber.Tree {

@Override
protected void log(int priority, String tag, String message, Throwable t) {
protected void log(int priority, String tag, @NonNull String message, Throwable t) {
if (priority == Log.VERBOSE || priority == Log.DEBUG) {
return;
}
Expand All @@ -39,7 +39,7 @@ protected void log(int priority, String tag, String message, Throwable t) {

if (t != null) {
Crashlytics.getInstance().core.logException(t);
FirebaseCrash.report(t);
Crashlytics.logException(t);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.TextView;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
Expand Down
145 changes: 110 additions & 35 deletions app/src/main/java/me/cutmail/disasterapp/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,30 @@
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;
import com.firebase.ui.database.FirebaseListAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

import com.firebase.ui.firestore.paging.FirestorePagingAdapter;
import com.firebase.ui.firestore.paging.FirestorePagingOptions;
import com.firebase.ui.firestore.paging.LoadingState;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.Query;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.paging.PagedList;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import hotchemi.android.rate.AppRate;
Expand All @@ -28,18 +37,26 @@
import timber.log.Timber;


public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
public class MainActivity extends AppCompatActivity {

@BindView(R.id.paging_recycler)
RecyclerView recyclerView;

@BindView(R.id.listView)
ListView listView;
@BindView(R.id.paging_loading)
ProgressBar progressBar;

private FirebaseListAdapter<Entry> adapter;
private FirebaseFirestore firestore;
private CollectionReference collectionReference;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);

firestore = FirebaseFirestore.getInstance();
collectionReference = firestore.collection("entries");

setupLayout();

Fabric.with(this, new Crashlytics());
Expand All @@ -48,15 +65,6 @@ protected void onCreate(Bundle savedInstanceState) {
AppRate.showRateDialogIfMeetsConditions(this);
}

@Override
protected void onDestroy() {
super.onDestroy();

if (adapter != null) {
adapter.cleanup();
}
}

private void setupRateDialog() {
AppRate.with(this).monitor();
}
Expand Down Expand Up @@ -85,15 +93,61 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

private void setupLayout() {
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("entries");
adapter = new FirebaseListAdapter<Entry>(this, Entry.class, android.R.layout.simple_list_item_1, ref) {
@Override
protected void populateView(View v, Entry entry, int position) {
((TextView) v.findViewById(android.R.id.text1)).setText(entry.getTitle());
Query query = collectionReference.orderBy("title");

PagedList.Config config = new PagedList.Config.Builder()
.setEnablePlaceholders(false)
.setPrefetchDistance(10)
.setPageSize(20)
.build();

FirestorePagingOptions<Entry> options = new FirestorePagingOptions.Builder<Entry>()
.setLifecycleOwner(this)
.setQuery(query, config, Entry.class)
.build();

FirestorePagingAdapter<Entry, ItemViewHolder> adapter = new FirestorePagingAdapter<Entry, ItemViewHolder>(options) {
@Override protected void onBindViewHolder(@NonNull ItemViewHolder holder, int position, @NonNull Entry entry) {
holder.bind(entry);
}

@NonNull @Override public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.entry_list_item, parent, false);
return new ItemViewHolder(view, new ItemViewHolder.OnEntryClickListener() {
@Override public void onItemClick(String title, String url) {
openEntry(title, url);
}
});
}

@Override protected void onLoadingStateChanged(@NonNull LoadingState state) {
switch (state) {
case LOADING_INITIAL:
case LOADING_MORE:
progressBar.setVisibility(View.VISIBLE);
break;
case LOADED:
progressBar.setVisibility(View.GONE);
break;
case FINISHED:
progressBar.setVisibility(View.GONE);
break;
case ERROR:
break;
}
}
};
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);

recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
DividerItemDecoration itemDecoration = new DividerItemDecoration(recyclerView.getContext(), new LinearLayoutManager(this).getOrientation());
recyclerView.addItemDecoration(itemDecoration);
}

public void openEntry(String title, String url) {
Intent intent = EntryDetailActivity.createIntent(this, title, url);
startActivity(intent);
}

private void openAbout() {
Expand All @@ -111,7 +165,7 @@ private void openInquiry() {
intent.putExtra(Intent.EXTRA_TEXT, "こちらにお問い合わせ内容をご記入ください。");
startActivity(intent);
} catch (ActivityNotFoundException e) {
Timber.e(e, e.getMessage());
Timber.e(e);
}
}

Expand All @@ -123,16 +177,37 @@ private void openPlayStore() {
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
} catch (ActivityNotFoundException e) {
Timber.e(e, e.getMessage());
Timber.e(e);
}
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (adapter != null) {
Entry entry = adapter.getItem(position);
Intent intent = EntryDetailActivity.createIntent(this, entry.getTitle(), entry.getUrl());
startActivity(intent);
static class ItemViewHolder extends RecyclerView.ViewHolder {

public interface OnEntryClickListener {
void onItemClick(String title, String url);
}

@BindView(R.id.container)
View mView;

@BindView(R.id.title)
TextView mTextView;

private final OnEntryClickListener listener;

ItemViewHolder(View itemView, OnEntryClickListener listener) {
super(itemView);
this.listener = listener;
ButterKnife.bind(this, itemView);
}

void bind(final Entry entry) {
mTextView.setText(entry.getTitle());
mView.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
listener.onItemClick(entry.getTitle(), entry.getUrl());
}
});
}
}
}
29 changes: 26 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listView"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
tools:context="me.cutmail.disasterapp.activity.MainActivity">

<ProgressBar
android:id="@+id/paging_loading"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-6dp"
android:background="@android:color/transparent"
android:indeterminate="true"
tools:ignore="NegativeMargin" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/paging_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/paging_loading"
android:clipToPadding="false"
tools:listitem="@layout/entry_list_item" />

</RelativeLayout>
Loading

0 comments on commit b72aa62

Please sign in to comment.