diff options
author | Trumeet <liangyuteng12345@gmail.com> | 2017-03-04 17:05:13 +0800 |
---|---|---|
committer | Trumeet <liangyuteng12345@gmail.com> | 2017-03-04 17:05:13 +0800 |
commit | aa114ac151730871e9384d5e9760afcc4a73eb15 (patch) | |
tree | f393f8da65475ec235dcf934a852a9b79777373c | |
download | MAT-BBS_Discuz_Android-aa114ac151730871e9384d5e9760afcc4a73eb15.tar MAT-BBS_Discuz_Android-aa114ac151730871e9384d5e9760afcc4a73eb15.tar.gz MAT-BBS_Discuz_Android-aa114ac151730871e9384d5e9760afcc4a73eb15.tar.bz2 MAT-BBS_Discuz_Android-aa114ac151730871e9384d5e9760afcc4a73eb15.zip |
First commit. Basic thread list and forum type list. Not support load-more.
46 files changed, 1766 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..39fb081 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="CompilerConfiguration"> + <resourceExtensions /> + <wildcardResourcePatterns> + <entry name="!?*.java" /> + <entry name="!?*.form" /> + <entry name="!?*.class" /> + <entry name="!?*.groovy" /> + <entry name="!?*.scala" /> + <entry name="!?*.flex" /> + <entry name="!?*.kt" /> + <entry name="!?*.clj" /> + <entry name="!?*.aj" /> + </wildcardResourcePatterns> + <annotationProcessing> + <profile default="true" name="Default" enabled="false"> + <processorPath useClasspath="true" /> + </profile> + </annotationProcessing> + </component> +</project>
\ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ +<component name="CopyrightManager"> + <settings default="" /> +</component>
\ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..7ac24c7 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="GradleSettings"> + <option name="linkedExternalProjectsSettings"> + <GradleProjectSettings> + <option name="distributionType" value="DEFAULT_WRAPPED" /> + <option name="externalProjectPath" value="$PROJECT_DIR$" /> + <option name="modules"> + <set> + <option value="$PROJECT_DIR$" /> + <option value="$PROJECT_DIR$/app" /> + </set> + </option> + <option name="resolveModulePerSourceSet" value="false" /> + </GradleProjectSettings> + </option> + </component> +</project>
\ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5d19981 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="EntryPointsManager"> + <entry_points version="2.0" /> + </component> + <component name="NullableNotNullManager"> + <option name="myDefaultNullable" value="android.support.annotation.Nullable" /> + <option name="myDefaultNotNull" value="android.support.annotation.NonNull" /> + <option name="myNullables"> + <value> + <list size="4"> + <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" /> + <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" /> + <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" /> + <item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" /> + </list> + </value> + </option> + <option name="myNotNulls"> + <value> + <list size="4"> + <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" /> + <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" /> + <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" /> + <item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" /> + </list> + </value> + </option> + </component> + <component name="ProjectLevelVcsManager" settingsEditedManually="false"> + <OptionsSetting value="true" id="Add" /> + <OptionsSetting value="true" id="Remove" /> + <OptionsSetting value="true" id="Checkout" /> + <OptionsSetting value="true" id="Update" /> + <OptionsSetting value="true" id="Status" /> + <OptionsSetting value="true" id="Edit" /> + <ConfirmationsSetting value="0" id="Add" /> + <ConfirmationsSetting value="0" id="Remove" /> + </component> + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> + <output url="file://$PROJECT_DIR$/build/classes" /> + </component> + <component name="ProjectType"> + <option name="id" value="Android" /> + </component> +</project>
\ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..58245e7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/MyAndroidToolsBBS.iml" filepath="$PROJECT_DIR$/MyAndroidToolsBBS.iml" /> + <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> + </modules> + </component> +</project>
\ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="RunConfigurationProducerService"> + <option name="ignoredProducers"> + <set> + <option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" /> + <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" /> + <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" /> + </set> + </option> + </component> +</project>
\ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..e484940 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,50 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 25 + buildToolsVersion "25.0.2" + defaultConfig { + applicationId "me.letitfly.mat" + minSdkVersion 21 + targetSdkVersion 25 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + debug { + buildConfigField "boolean", "DEBUG_LOG", "true" + } + release { + buildConfigField "boolean", "DEBUG_LOG", "false" + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + testCompile 'junit:junit:4.12' + // ui + compile 'com.android.support:design:25.2.0' + compile 'com.android.support:appcompat-v7:25.2.0' + compile 'de.hdodenhof:circleimageview:2.1.0' + compile 'com.github.stfalcon:chatkit:0.1.2' + // retrofit rx + compile 'io.reactivex:rxjava:1.1.0' + compile 'io.reactivex:rxandroid:1.1.0' + compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4' + compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4' + compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4' + compile 'com.squareup.okhttp3:logging-interceptor:3.2.0' + // butter knife + compile 'com.jakewharton:butterknife:8.5.1' + annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1' + // bottom sheet + compile 'com.flipboard:bottomsheet-core:1.5.3' + compile 'com.flipboard:bottomsheet-commons:1.5.3' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..ddec642 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\Trumeet\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/src/androidTest/java/me/letitfly/mat/ExampleInstrumentedTest.java b/app/src/androidTest/java/me/letitfly/mat/ExampleInstrumentedTest.java new file mode 100644 index 0000000..643b3fc --- /dev/null +++ b/app/src/androidTest/java/me/letitfly/mat/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package me.letitfly.mat; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("me.letitfly.mat", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..6c71c06 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="me.letitfly.mat"> + <uses-permission android:name="android.permission.INTERNET" /> + <application + android:allowBackup="true" + android:icon="@mipmap/ic_launcher" + android:label="@string/app_name" + android:supportsRtl="true" + android:theme="@style/AppTheme"> + <activity android:name=".MainActivity" + android:theme="@style/AppTheme.NoActionBar"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> + +</manifest>
\ No newline at end of file diff --git a/app/src/main/java/me/letitfly/mat/MainActivity.java b/app/src/main/java/me/letitfly/mat/MainActivity.java new file mode 100644 index 0000000..ff5ecff --- /dev/null +++ b/app/src/main/java/me/letitfly/mat/MainActivity.java @@ -0,0 +1,154 @@ +package me.letitfly.mat; + +import android.os.Bundle; +import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.widget.TextView; + +import com.flipboard.bottomsheet.BottomSheetLayout; + +import me.letitfly.mat.utils.ForumSwitchUtils; +import me.letitfly.mat.utils.ProgressSubscriber; +import rx.Subscriber; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; +import me.letitfly.mat.api.APIManager; +import me.letitfly.mat.fragments.PostListFragment; +import me.letitfly.mat.model.ForumNav; +import me.letitfly.mat.utils.Logger; +import rx.Observable; + +public class MainActivity extends AppCompatActivity { + private static final String TAG = MainActivity.class.getSimpleName(); + + @BindView(R.id.toolbar_title) + TextView mToolBarTitle; + @BindView(R.id.swipe) + SwipeRefreshLayout mRefreshLayout; + @BindView(R.id.toolbar) + Toolbar mToolbar; + + private Subscriber<ForumNav> mRefreshForumsConsumer; + + // Forum fragment list + private ArrayList<ForumNav.Forum> mForums; + private List<PostListFragment> mPostListFragments; + private int mCurrentForumIndex = -1; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + ButterKnife.bind(this); + setSupportActionBar(mToolbar); + getSupportActionBar().setDisplayShowTitleEnabled(false); + mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + if (mCurrentForumIndex == -1) { + refreshForums(); + } else { + mRefreshLayout.setRefreshing(true); + refreshCurrent(); + } + } + }); + refreshForums(); + } + + private void refreshCurrent () { + mPostListFragments.get(mCurrentForumIndex).refresh(new PostListFragment.RefreshListener() { + @Override + public void finish() { + mRefreshLayout.setRefreshing(false); + mRefreshLayout.setEnabled(false); + } + + @Override + public void err() { + mRefreshLayout.setRefreshing(false); + } + }); + } + + private void refreshForums () { + if (mRefreshForumsConsumer != null) { + mRefreshForumsConsumer.unsubscribe(); + } + mRefreshLayout.setRefreshing(true); + ProgressSubscriber.SubscriberOnNextListener<ForumNav> listener + = new ProgressSubscriber.SubscriberOnNextListener<ForumNav>() { + @Override + public void onNext(ForumNav forumNav) { + List<ForumNav.Forum> forumList = Arrays.asList(forumNav.getForums()); + if (mForums != null) + mForums.clear(); + else + mForums = new ArrayList<>(); + for (ForumNav.Forum forum : forumList) { + if ("forum".equals(forum.getType())) { + mForums.add(forum); + } + } + if (mPostListFragments != null) + mPostListFragments.clear(); + mPostListFragments = new ArrayList<>(); + for (ForumNav.Forum forum : mForums) { + mPostListFragments.add(PostListFragment.newInstance(forum)); + } + switchForum(0); + + mToolBarTitle.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (mRefreshLayout.isRefreshing()) { + Logger.e(TAG, "Refreshing, not show sheet"); + return; + } + Logger.i(TAG, "Showing bottom sheet"); + BottomSheetLayout bottomSheet = (BottomSheetLayout)findViewById(R.id.bottomsheet); + ForumSwitchUtils.pickTags(bottomSheet, new ForumSwitchUtils.OnTagSelectedListener() { + @Override + public void onSelected(ForumNav.Forum forum) { + switchForum(mForums.indexOf(forum)); + } + + @Override + public void onSpecialSelected(int id) { + // DZ BBS Not support "All" tag. + } + }, mForums); + } + }); + mRefreshLayout.setRefreshing(false); + } + + @Override + public void onError(Throwable e) { + mRefreshLayout.setRefreshing(false); + // TODO: Show error + } + }; + mRefreshForumsConsumer = new ProgressSubscriber<>(listener); + APIManager.getForums(0, mRefreshForumsConsumer); + } + + private void switchForum (int index) { + mCurrentForumIndex = index; + ForumNav.Forum forum = mForums.get(index); + Logger.i(TAG, forum.toString()); + mToolBarTitle.setText(forum.getName()); + getFragmentManager().beginTransaction() + .replace(R.id.frame, mPostListFragments.get(index)) + .commitAllowingStateLoss(); + mRefreshLayout.setEnabled(true); + refreshCurrent(); + } +} diff --git a/app/src/main/java/me/letitfly/mat/api/APIInterface.java b/app/src/main/java/me/letitfly/mat/api/APIInterface.java new file mode 100644 index 0000000..ec5073f --- /dev/null +++ b/app/src/main/java/me/letitfly/mat/api/APIInterface.java @@ -0,0 +1,21 @@ +package me.letitfly.mat.api; + +import me.letitfly.mat.api.model.HttpResult; +import me.letitfly.mat.model.ForumDisplay; +import me.letitfly.mat.model.ForumNav; +import retrofit2.http.GET; +import retrofit2.http.Query; +import rx.Observable; + +/** + * Created by Trumeet on 2017/3/2. + * Mat Bbs Api + * @author Trumeet + */ + +interface APIInterface { + @GET("mobile/index.php?version=4&module=forumnav") + Observable<HttpResult<ForumNav>> nav (@Query("page") int page); + @GET("mobile/index.php?version=4&module=forumdisplay") + Observable<HttpResult<ForumDisplay>> display (@Query("fid") int fid, @Query("page") int page); +} diff --git a/app/src/main/java/me/letitfly/mat/api/APIManager.java b/app/src/main/java/me/letitfly/mat/api/APIManager.java new file mode 100644 index 0000000..f5be32a --- /dev/null +++ b/app/src/main/java/me/letitfly/mat/api/APIManager.java @@ -0,0 +1,86 @@ +package me.letitfly.mat.api; + +import me.letitfly.mat.api.exception.ApiException; +import me.letitfly.mat.api.model.HttpResult; +import me.letitfly.mat.model.ForumDisplay; +import me.letitfly.mat.model.ForumNav; +import me.letitfly.mat.utils.Logger; +import okhttp3.OkHttpClient; +import okhttp3.logging.HttpLoggingInterceptor; +import retrofit2.Retrofit; +import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; +import retrofit2.converter.gson.GsonConverterFactory; +import rx.Observable; +import rx.Subscriber; +import rx.android.schedulers.AndroidSchedulers; +import rx.functions.Func1; +import rx.schedulers.Schedulers; + +import static me.letitfly.mat.BuildConfig.DEBUG; + +/** + * Created by Trumeet on 2017/3/2. + * API Interface manager + * @see APIInterface + * @author Trumeet + */ + +public class APIManager { + private static final String TAG = "API"; + private static Retrofit getBaseRetrofit () { + Logger.i(TAG, "-> getBaseRetrofit"); + Retrofit.Builder builder = new Retrofit.Builder() + .baseUrl("https://mat.letitfly.me/api/") + .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) + .addConverterFactory(GsonConverterFactory.create()); + if (DEBUG) { + HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); + interceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS); + OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build(); + builder.client(client); + } + return builder.build(); + } + + private static APIInterface getInterface () { + return getBaseRetrofit().create(APIInterface.class); + } + + public static void getForumDisplay (int fid, int page, Subscriber<ForumDisplay> subscriber) { + Logger.i(TAG, "-> getForumDisplay"); + toSubscribe(getInterface().display(fid, page) + .map(new HttpResultFunc<ForumDisplay>()), subscriber); + } + + public static void getForums(int page, Subscriber<ForumNav> subscriber) { + Logger.i(TAG, "-> getForums"); + toSubscribe(getInterface().nav(page) + .map(new HttpResultFunc<ForumNav>()), subscriber); + } + + //添加线程管理并订阅 + @SuppressWarnings("unchecked") + private static void toSubscribe(Observable o, Subscriber s){ + o.subscribeOn(Schedulers.io()) + .unsubscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(s); + } + + /** + * 用来统一处理Http的resultCode,并将HttpResult的Data部分剥离出来返回给subscriber + * + * @param <T> Subscriber真正需要的数据类型,也就是Data部分的数据类型 + */ + private static class HttpResultFunc<T> implements Func1<HttpResult<T>, T> { + + @Override + public T call(HttpResult<T> httpResult) throws ApiException{ + if (!httpResult.isSuccess()) { + throw new ApiException(httpResult.getError()); + } + return httpResult.getData(); + } + } + +} diff --git a/app/src/main/java/me/letitfly/mat/api/exception/ApiException.java b/app/src/main/java/me/letitfly/mat/api/exception/ApiException.java new file mode 100644 index 0000000..55c996b --- /dev/null +++ b/app/src/main/java/me/letitfly/mat/api/exception/ApiException.java @@ -0,0 +1,26 @@ +package me.letitfly.mat.api.exception; + +/** + * Created by Trumeet on 2017/3/4. + * Forum api exception, throw when HttpResult unsuccessful. + * @see me.letitfly.mat.api.model.HttpResult + * @author Trumeet + */ + +public class ApiException extends RuntimeException { + public ApiException() { + super(); + } + + public ApiException(String message) { + super(message); + } + + public ApiException(String message, Throwable cause) { + super(message, cause); + } + + public ApiException(Throwable cause) { + super(cause); + } +} diff --git a/app/src/main/java/me/letitfly/mat/api/model/HttpResult.java b/app/src/main/java/me/letitfly/mat/api/model/HttpResult.java new file mode 100644 index 0000000..30d81e6 --- /dev/null +++ b/app/src/main/java/me/letitfly/mat/api/model/HttpResult.java @@ -0,0 +1,25 @@ +package me.letitfly.mat.api.model; + +/** + * Created by Trumeet on 2017/3/4. + */ + +public class HttpResult<T> { + private int Version; + private String Charset; + private String error = ""; + + private T Variables; + + public boolean isSuccess () { + return error == null || error.isEmpty(); + } + + public T getData () { + return Variables; + } + + public String getError () { + return error; + } +}
\ No newline at end of file diff --git a/app/src/main/java/me/letitfly/mat/fragments/PostListFragment.java b/app/src/main/java/me/letitfly/mat/fragments/PostListFragment.java new file mode 100644 index 0000000..66b632e --- /dev/null +++ b/app/src/main/java/me/letitfly/mat/fragments/PostListFragment.java @@ -0,0 +1,106 @@ +package me.letitfly.mat.fragments; + +import android.app.Fragment; +import android.app.ListFragment; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import java.util.Arrays; +import java.util.List; + +import me.letitfly.mat.api.APIManager; +import me.letitfly.mat.model.ForumDisplay; +import me.letitfly.mat.model.ForumNav; +import me.letitfly.mat.utils.Logger; +import me.letitfly.mat.utils.ProgressSubscriber; +import me.letitfly.mat.utils.adapters.ThreadListAdapter; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import rx.Observable; +import rx.Subscriber; + +/** + * Created by Trumeet on 2017/3/2. + * @author Trumeet + */ + +public class PostListFragment extends ListFragment { + private static final String TAG = "PostListFragment"; + private static final String EXTRA_FORUM = + PostListFragment.class.getSimpleName() + + ".EXTRA_FORUM"; + + private List<ForumDisplay.Thread> mThreadList; + private ThreadListAdapter mAdapter; + private Subscriber<ForumDisplay> mGetListSubscriber; + + private ForumNav.Forum mForum; + + public void onCreate (Bundle savedInstanceState){ + super.onCreate(savedInstanceState); + mForum = getArguments().getParcelable(EXTRA_FORUM); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + refresh(null); + } + + @Override + public void onDestroy() { + if (mGetListSubscriber != null) + mGetListSubscriber.unsubscribe(); + super.onDestroy(); + } + + public static PostListFragment newInstance (ForumNav.Forum forum) { + PostListFragment fragment = new PostListFragment(); + Bundle args = new Bundle(); + args.putParcelable(EXTRA_FORUM, forum); + fragment.setArguments(args); + return fragment; + } + + public interface RefreshListener { + void finish(); + void err(); + } + + public synchronized void refresh (@Nullable final RefreshListener refreshListener) { + Logger.i(TAG, "-> refresh"); + if (mGetListSubscriber != null) + mGetListSubscriber.unsubscribe(); + setListAdapter(null); + mAdapter = null; + ProgressSubscriber.SubscriberOnNextListener<ForumDisplay> listener + = new ProgressSubscriber.SubscriberOnNextListener<ForumDisplay>() { + @Override + public void onNext(ForumDisplay display) { + ForumDisplay.Thread[] threads = display.getForum_threadlist(); + mThreadList = Arrays.asList(threads); + mAdapter = new ThreadListAdapter(getActivity(), mThreadList); + getListView().setAdapter(mAdapter); + if (refreshListener != null) + refreshListener.finish(); + } + + @Override + public void onError(Throwable e) { + // TODO: Show error + if (refreshListener != null) + refreshListener.err(); + } + }; + mGetListSubscriber = new ProgressSubscriber<>(listener); + int fid = Integer.parseInt(mForum.getFid()); + Logger.i(TAG, "Refresh -> fid:" + fid); + APIManager.getForumDisplay( + fid + , 0, mGetListSubscriber); + } +} diff --git a/app/src/main/java/me/letitfly/mat/model/ForumDisplay.java b/app/src/main/java/me/letitfly/mat/model/ForumDisplay.java new file mode 100644 index 0000000..48cdedf --- /dev/null +++ b/app/src/main/java/me/letitfly/mat/model/ForumDisplay.java @@ -0,0 +1,367 @@ +package me.letitfly.mat.model; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * Created by Trumeet on 2017/3/2. + * forumdisplay + * @author Trumeet + */ + +public class ForumDisplay implements Parcelable{ + private String tpp; + + protected ForumDisplay(Parcel in) { + tpp = in.readString(); + page = in.readString(); + reward_unit = in.readString(); + forum = in.readParcelable(Forum.class.getClassLoader()); + forum_threadlist = in.createTypedArray(Thread.CREATOR); + } + + public static final Creator<ForumDisplay> CREATOR = new Creator<ForumDisplay>() { + @Override + public ForumDisplay createFromParcel(Parcel in) { + return new ForumDisplay(in); + } + + @Override + public ForumDisplay[] newArray(int size) { + return new ForumDisplay[size]; + } + }; + + public String getTpp() { + return tpp; + } + + public String getPage() { + return page; + } + + public String getReward_unit() { + return reward_unit; + } + + public Forum getForum() { + return forum; + } + + public Thread[] getForum_threadlist() { + return forum_threadlist; + } + + private String page; + private String reward_unit; + private Forum forum; + private Thread[] forum_threadlist; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(tpp); + parcel.writeString(page); + parcel.writeString(reward_unit); + parcel.writeParcelable(forum, i); + parcel.writeTypedArray(forum_threadlist, i); + } + + public static class Thread implements Parcelable { + public String getTid() { + return tid; + } + + public String getTypeid() { + return typeid; + } + + public String getReadperm() { + return readperm; + } + + public String getPrice() { + return price; + } + + public String getAuthor() { + return author; + } + + public String getAuthorid() { + return authorid; + } + + public String getSubject() { + return subject; + } + + public String getDateline() { + return dateline; + } + + public String getLastpost() { + return lastpost; + } + + public String getLastposter() { + return lastposter; + } + + public String getViews() { + return views; + } + + public String getReplies() { + return replies; + } + + public String getDisplayorder() { + return displayorder; + } + + public String getDigest() { + return digest; + } + + public String getSpecial() { + return special; + } + + public String getAttachment() { + return attachment; + } + + public String getRecommend_add() { + return recommend_add; + } + + public String getReplycredit() { + return replycredit; + } + + public String getDbdateline() { + return dbdateline; + } + + public String getDblastpost() { + return dblastpost; + } + + public String getRushreply() { + return rushreply; + } + + public Reply[] getReply() { + return reply; + } + + private String tid; + private String typeid; + private String readperm; + private String price; + private String author; + private String authorid; + private String subject; + private String dateline; + private String lastpost; + private String lastposter; + private String views; + private String replies; + private String displayorder; + private String digest; + private String special; + private String attachment; + private String recommend_add; + private String replycredit; + private String dbdateline; + private String dblastpost; + private String rushreply; + private Reply[] reply; + + public static class Reply implements Parcelable { + private String pid; + private String author; + private String authorid; + private String message; + + public String getPid() { + return pid; + } + + public void setPid(String pid) { + this.pid = pid; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public String getAuthorid() { + return authorid; + } + + public void setAuthorid(String authorid) { + this.authorid = authorid; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + protected Reply(Parcel in) { + pid = in.readString(); + author = in.readString(); + authorid = in.readString(); + message = in.readString(); + } + + public static final Creator<Reply> CREATOR = new Creator<Reply>() { + @Override + public Reply createFromParcel(Parcel in) { + return new Reply(in); + } + + @Override + public Reply[] newArray(int size) { + return new Reply[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(pid); + parcel.writeString(author); + parcel.writeString(authorid); + parcel.writeString(message); + } + } + + protected Thread(Parcel in) { + tid = in.readString(); + typeid = in.readString(); + readperm = in.readString(); + price = in.readString(); + author = in.readString(); + authorid = in.readString(); + subject = in.readString(); + dateline = in.readString(); + lastpost = in.readString(); + lastposter = in.readString(); + views = in.readString(); + replies = in.readString(); + displayorder = in.readString(); + digest = in.readString(); + special = in.readString(); + attachment = in.readString(); + recommend_add = in.readString(); + replycredit = in.readString(); + dbdateline = in.readString(); + dblastpost = in.readString(); + rushreply = in.readString(); + reply = in.createTypedArray(Reply.CREATOR); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(tid); + dest.writeString(typeid); + dest.writeString(readperm); + dest.writeString(price); + dest.writeString(author); + dest.writeString(authorid); + dest.writeString(subject); + dest.writeString(dateline); + dest.writeString(lastpost); + dest.writeString(lastposter); + dest.writeString(views); + dest.writeString(replies); + dest.writeString(displayorder); + dest.writeString(digest); + dest.writeString(special); + dest.writeString(attachment); + dest.writeString(recommend_add); + dest.writeString(replycredit); + dest.writeString(dbdateline); + dest.writeString(dblastpost); + dest.writeString(rushreply); + dest.writeTypedArray(reply, flags); + } + + @Override + public int describeContents() { + return 0; + } + + public static final Creator<Thread> CREATOR = new Creator<Thread>() { + @Override + public Thread createFromParcel(Parcel in) { + return new Thread(in); + } + + @Override + public Thread[] newArray(int size) { + return new Thread[size]; + } + }; + } + + private static class Forum implements Parcelable { + private String fid; + private String description; + private String rules; + private String name; + private String threads; + + protected Forum(Parcel in) { + fid = in.readString(); + description = in.readString(); + rules = in.readString(); + name = in.readString(); + threads = in.readString(); + } + + public static final Creator<Forum> CREATOR = new Creator<Forum>() { + @Override + public Forum createFromParcel(Parcel in) { + return new Forum(in); + } + + @Override + public Forum[] newArray(int size) { + return new Forum[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(fid); + parcel.writeString(description); + parcel.writeString(rules); + parcel.writeString(name); + parcel.writeString(threads); + } + } +} diff --git a/app/src/main/java/me/letitfly/mat/model/ForumNav.java b/app/src/main/java/me/letitfly/mat/model/ForumNav.java new file mode 100644 index 0000000..523d6a5 --- /dev/null +++ b/app/src/main/java/me/letitfly/mat/model/ForumNav.java @@ -0,0 +1,115 @@ +package me.letitfly.mat.model; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * Created by Trumeet on 2017/3/2. + * A forum. + * @author Trumeet + */ + +public class ForumNav implements Parcelable{ + private Forum[] forums; + public Forum[] getForums () { + return forums; + } + + protected ForumNav(Parcel in) { + forums = in.createTypedArray(Forum.CREATOR); + } + + public static final Creator<ForumNav> CREATOR = new Creator<ForumNav>() { + @Override + public ForumNav createFromParcel(Parcel in) { + return new ForumNav(in); + } + + @Override + public ForumNav[] newArray(int size) { + return new ForumNav[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeTypedArray(forums, i); + } + + public static class Forum implements Parcelable{ + String fid; + String type; + String name; + String fup; + String status; + + @Override + public String toString () { + return String.valueOf(getFid()); + } + + public String getFid() { + return fid; + } + + public String getType() { + return type; + } + + public String getName() { + return name; + } + + public String getFup() { + return fup; + } + + public String getStatus() { + return status; + } + + protected Forum(Parcel in) { + fid = in.readString(); + type = in.readString(); + name = in.readString(); + fup = in.readString(); + status = in.readString(); + } + + public static final Creator<Forum> CREATOR = new Creator<Forum>() { + @Override + public Forum createFromParcel(Parcel in) { + return new Forum(in); + } + + @Override + public Forum[] newArray(int size) { + return new Forum[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(fid); + parcel.writeString(type); + parcel.writeString(name); + parcel.writeString(fup); + parcel.writeString(status); + } + } + + @Override + public String toString () { + return "Forums:" + forums.length; + } +} diff --git a/app/src/main/java/me/letitfly/mat/utils/ForumSwitchUtils.java b/app/src/main/java/me/letitfly/mat/utils/ForumSwitchUtils.java new file mode 100644 index 0000000..a5fdfec --- /dev/null +++ b/app/src/main/java/me/letitfly/mat/utils/ForumSwitchUtils.java @@ -0,0 +1,59 @@ +package me.letitfly.mat.utils; + +import android.view.MenuItem; + +import com.flipboard.bottomsheet.BottomSheetLayout; +import com.flipboard.bottomsheet.commons.MenuSheetView; + +import java.util.List; + +import me.letitfly.mat.R; +import me.letitfly.mat.model.ForumNav; + +/** + * Created by Trumeet on 2017/3/4. + * Create a bottom sheet to switch forums. + * @author Trumeet + */ + +public class ForumSwitchUtils { + public static final int ID_ALL = -1; + + public interface OnTagSelectedListener { + void onSelected (ForumNav.Forum forum); + void onSpecialSelected (int id); + } + + public static void pickTags (final BottomSheetLayout layout + , final OnTagSelectedListener listener + , final List<ForumNav.Forum> forumList) { + MenuSheetView view = new MenuSheetView(layout.getContext() + , MenuSheetView.MenuType.GRID + , R.string.title_forums + , new MenuSheetView.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + if (item.getItemId() == ID_ALL) { + listener.onSpecialSelected(item.getItemId()); + layout.dismissSheet(); + return true; + } + listener.onSelected(forumList.get(item.getItemId())); + layout.dismissSheet(); + return true; + } + }); + // DZ BBS Not support "All" tag. + /* + view.getMenu().add(0, ID_ALL, 0, R.string.filter_all) + .setIcon(R.drawable.ic_apps_black_24dp); + */ + for (int i = 0; i < forumList.size(); i ++) { + ForumNav.Forum forum = forumList.get(i); + // TODO: Icon load + view.getMenu().add(0, i, 0, forum.getName()); + } + view.updateMenu(); + layout.showWithSheetView(view); + } +} diff --git a/app/src/main/java/me/letitfly/mat/utils/Logger.java b/app/src/main/java/me/letitfly/mat/utils/Logger.java new file mode 100644 index 0000000..399be60 --- /dev/null +++ b/app/src/main/java/me/letitfly/mat/utils/Logger.java @@ -0,0 +1,37 @@ +package me.letitfly.mat.utils; + +import android.util.Log; + +import static me.letitfly.mat.BuildConfig.DEBUG_LOG; + +/** + * Created by Trumeet on 2017/3/2. + * Log util + * @author Trumeet + */ + +public class Logger { + public static void i (String tag, String message) { + if (DEBUG_LOG) Log.i(tag, message); + } + + public static void i (String tag, String message, Throwable throwable) { + if (DEBUG_LOG) Log.i(tag, message, throwable); + } + + public static void w (String tag, String message) { + if (DEBUG_LOG) Log.w(tag, message); + } + + public static void w (String tag, String message, Throwable throwable) { + if (DEBUG_LOG) Log.w(tag, message, throwable); + } + + public static void e (String tag, String message) { + if (DEBUG_LOG) Log.e(tag, message); + } + + public static void e (String tag, String message, Throwable throwable) { + if (DEBUG_LOG) Log.e(tag, message, throwable); + } +} diff --git a/app/src/main/java/me/letitfly/mat/utils/ProgressSubscriber.java b/app/src/main/java/me/letitfly/mat/utils/ProgressSubscriber.java new file mode 100644 index 0000000..e4a5856 --- /dev/null +++ b/app/src/main/java/me/letitfly/mat/utils/ProgressSubscriber.java @@ -0,0 +1,36 @@ +package me.letitfly.mat.utils; + +import rx.Subscriber; + +public class ProgressSubscriber<T> extends Subscriber<T> { + private static final String TAG = "ProgressSubscriber"; + public interface SubscriberOnNextListener<T> { + void onNext(T t); + void onError (Throwable e); + } + private SubscriberOnNextListener<T> mSubscriberOnNextListener; + + public ProgressSubscriber(SubscriberOnNextListener<T> mSubscriberOnNextListener) { + this.mSubscriberOnNextListener = mSubscriberOnNextListener; + } + + @Override + public void onStart() { + } + + @Override + public void onCompleted() { + Logger.i(TAG, "onCompleted"); + } + + @Override + public void onError(Throwable e) { + Logger.e(TAG, "onError", e); + mSubscriberOnNextListener.onError(e); + } + + @Override + public void onNext(T t) { + mSubscriberOnNextListener.onNext(t); + } +}
\ No newline at end of file diff --git a/app/src/main/java/me/letitfly/mat/utils/adapters/ThreadListAdapter.java b/app/src/main/java/me/letitfly/mat/utils/adapters/ThreadListAdapter.java new file mode 100644 index 0000000..c3c9e69 --- /dev/null +++ b/app/src/main/java/me/letitfly/mat/utils/adapters/ThreadListAdapter.java @@ -0,0 +1,55 @@ +package me.letitfly.mat.utils.adapters; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +import java.util.List; + +import me.letitfly.mat.R; +import me.letitfly.mat.model.ForumDisplay; + +/** + * Created by Trumeet on 2017/3/2. + * Thread list array adapter. + * @see me.letitfly.mat.fragments.PostListFragment + * @see android.widget.ArrayAdapter + * @see me.letitfly.mat.model.ForumDisplay + * @author Trumeet + */ + +public class ThreadListAdapter extends ArrayAdapter { + private Context mContext; + private List<ForumDisplay.Thread> mThreadList; + + public ThreadListAdapter (Context context, List<ForumDisplay.Thread> list) { + super(context, 0, list); + mContext = context; + mThreadList = list; + } + + @NonNull + @Override + public View getView(int position, View convertView, ViewGroup parent) { + if (convertView == null) { + convertView = LayoutInflater.from(mContext).inflate(R.layout.item_discussion, parent, false); + } + ForumDisplay.Thread discussion = mThreadList.get(position); + + TextView title = (TextView) convertView.findViewById(android.R.id.text1); + title.setText(discussion.getSubject()); + + //CircleImageView avatar = (CircleImageView) convertView.findViewById(R.id.avatar); + //NetworkUtil.loadImage(discussion, avatar); + + TextView context = (TextView) convertView.findViewById(android.R.id.text2); + context.setText(mContext.getString(R.string.text_post_summary + , discussion.getLastposter(), discussion.getLastpost())); + + return convertView; + } +} diff --git a/app/src/main/res/drawable/ic_apps_black_24dp.xml b/app/src/main/res/drawable/ic_apps_black_24dp.xml new file mode 100644 index 0000000..ff485cf --- /dev/null +++ b/app/src/main/res/drawable/ic_apps_black_24dp.xml @@ -0,0 +1,9 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + <path + android:fillColor="#FF000000" + android:pathData="M4,8h4L8,4L4,4v4zM10,20h4v-4h-4v4zM4,20h4v-4L4,16v4zM4,14h4v-4L4,10v4zM10,14h4v-4h-4v4zM16,4v4h4L20,4h-4zM10,8h4L14,4h-4v4zM16,14h4v-4h-4v4zM16,20h4v-4h-4v4z"/> +</vector> diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..f82c4f1 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" android:layout_height="match_parent"> + <android.support.v7.widget.Toolbar + android:id="@+id/toolbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="@color/colorPrimary" + xmlns:app="http://schemas.android.com/apk/res-auto" + app:titleTextColor="#000" > + <TextView + android:textAppearance="@style/TextAppearance.AppCompat.Title" + android:textColor="#000" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/app_name" + android:id="@+id/toolbar_title" /> + </android.support.v7.widget.Toolbar> + + <android.support.v4.widget.SwipeRefreshLayout + android:id="@+id/swipe" + android:layout_below="@+id/toolbar" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_alignParentBottom="true" + android:layout_alignParentStart="true"> + <FrameLayout + android:id="@+id/frame" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + </android.support.v4.widget.SwipeRefreshLayout> + <include + layout="@layout/layout_bottom_tags" /> +</RelativeLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/item_discussion.xml b/app/src/main/res/layout/item_discussion.xml new file mode 100644 index 0000000..55e48b1 --- /dev/null +++ b/app/src/main/res/layout/item_discussion.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="72dp" + android:paddingEnd="16dp"> + <de.hdodenhof.circleimageview.CircleImageView + android:id="@+id/avatar" + android:layout_centerVertical="true" + android:paddingStart="16dp" + android:src="@mipmap/ic_launcher" + android:layout_width="@dimen/post_item_avatar_width" + android:layout_height="@dimen/post_item_avatar_height" /> + <RelativeLayout + android:layout_centerVertical="true" + android:paddingStart="72dp" + android:layout_width="wrap_content" + android:layout_height="wrap_content"> + <TextView + android:textSize="17sp" + android:textColor="#000" + android:text="@string/app_name" + android:id="@android:id/text1" + android:layout_width="wrap_content" + android:layout_height="wrap_content" /> + <TextView + android:layout_below="@android:id/text1" + android:textSize="16sp" + android:layout_centerVertical="true" + android:text="@string/app_name" + android:id="@android:id/text2" + android:layout_width="wrap_content" + android:layout_height="wrap_content" /> + </RelativeLayout> +</RelativeLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/layout_bottom_tags.xml b/app/src/main/res/layout/layout_bottom_tags.xml new file mode 100644 index 0000000..0ff9257 --- /dev/null +++ b/app/src/main/res/layout/layout_bottom_tags.xml @@ -0,0 +1,10 @@ +<com.flipboard.bottomsheet.BottomSheetLayout android:id="@+id/bottomsheet" + android:layout_width="match_parent" + android:layout_height="match_parent" + xmlns:android="http://schemas.android.com/apk/res/android"> + + <RelativeLayout + android:layout_width="match_parent" + android:layout_height="match_parent"/> + +</com.flipboard.bottomsheet.BottomSheetLayout>
\ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..cde69bc --- /dev/null +++ b/app/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..c133a0c --- /dev/null +++ b/app/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..bfa42f0 --- /dev/null +++ b/app/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..324e72c --- /dev/null +++ b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..aee44e1 --- /dev/null +++ b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..63fc816 --- /dev/null +++ b/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ +<resources> + <!-- Example customization of dimensions originally defined in res/values/dimens.xml + (such as screen margins) for screens with more than 820dp of available width. This + would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> + <dimen name="activity_horizontal_margin">64dp</dimen> +</resources> diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..45e367d --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <color name="colorPrimary">#FAFAFA</color> + <color name="colorPrimaryDark">#F5F5F5</color> + <color name="colorAccent">#FF4081</color> +</resources> diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..fae5ee8 --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,8 @@ +<resources> + <!-- Default screen margins, per the Android Design guidelines. --> + <dimen name="activity_horizontal_margin">16dp</dimen> + <dimen name="activity_vertical_margin">16dp</dimen> + <!-- Default avatar size --> + <dimen name="post_item_avatar_height">48dp</dimen> + <dimen name="post_item_avatar_width">48dp</dimen> +</resources> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..b9dabcb --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,11 @@ +<resources> + <string name="app_name">MyAndroidToolsBBS</string> + + <!-- For Thread List --> + <!-- 主题小标题。 Trumeet 5天前 --> + <string name="text_post_summary">%1$s %2$s</string> + + <!-- For Forum Switcher --> + <string name="title_forums">Forums</string> + <string name="filter_all">All</string> +</resources> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..d234dcd --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,12 @@ +<resources xmlns:tools="http://schemas.android.com/tools"> + <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> + <item name="colorPrimary">@color/colorPrimary</item> + <item name="colorPrimaryDark">@color/colorPrimaryDark</item> + <item name="colorAccent">@color/colorAccent</item> + <item name="android:windowLightStatusBar" tools:targetApi="m">true</item> + </style> + <style name="AppTheme.NoActionBar" parent="AppTheme"> + <item name="windowNoTitle">true</item> + <item name="windowActionBar">false</item> + </style> +</resources> diff --git a/app/src/test/java/me/letitfly/mat/ExampleUnitTest.java b/app/src/test/java/me/letitfly/mat/ExampleUnitTest.java new file mode 100644 index 0000000..e30f64b --- /dev/null +++ b/app/src/test/java/me/letitfly/mat/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package me.letitfly.mat; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } +}
\ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..74b2ab0 --- /dev/null +++ b/build.gradle @@ -0,0 +1,23 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:2.2.3' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + jcenter() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..11c6433 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,18 @@ +## Project-wide Gradle settings. +# +# For more details on how to configure your build environment visit +# 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. +# Default value: -Xmx1024m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +# +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +#Thu Mar 02 12:44:35 CST 2017 +systemProp.http.proxyHost=127.0.0.1 +org.gradle.jvmargs=-Xmx1536m +systemProp.http.proxyPort=1080 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar Binary files differnew file mode 100644 index 0000000..13372ae --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.jar diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..04e285f --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Dec 28 10:00:20 PST 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..e7b4def --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include ':app' |