forked from cheikh-wang/LazyWaimai-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cheikh
committed
Jan 12, 2017
1 parent
aca818c
commit 1f3bdcc
Showing
293 changed files
with
16,508 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/wanghong/Library/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 *; | ||
#} |
24 changes: 24 additions & 0 deletions
24
app/src/androidTest/java/com/cheikh/lazywaimai/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.cheikh.lazywaimai; | ||
|
||
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("com.cheikh.lazywaimai", appContext.getPackageName()); | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
app/src/main/java/com/cheikh/lazywaimai/base/BaseController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package com.cheikh.lazywaimai.base; | ||
|
||
import android.util.Log; | ||
import com.google.common.base.Preconditions; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.CopyOnWriteArraySet; | ||
import com.cheikh.lazywaimai.context.AppConfig; | ||
import com.cheikh.lazywaimai.model.bean.ResponseError; | ||
import com.cheikh.lazywaimai.ui.Display; | ||
|
||
/** | ||
* author: cheikh.wang on 17/1/5 | ||
* email: [email protected] | ||
*/ | ||
public abstract class BaseController<U extends BaseController.Ui<UC>, UC> { | ||
|
||
private final Set<U> mUis; | ||
private final Set<U> mUnmodifiableUis; | ||
|
||
private Display mDisplay; | ||
private boolean mInited; | ||
|
||
public BaseController() { | ||
mUis = new CopyOnWriteArraySet<>(); | ||
mUnmodifiableUis = Collections.unmodifiableSet(mUis); | ||
} | ||
|
||
public final void init() { | ||
Preconditions.checkState(!mInited, "Already inited"); | ||
onInited(); | ||
mInited = true; | ||
} | ||
|
||
public final void suspend() { | ||
Preconditions.checkState(mInited, "Not inited"); | ||
onSuspended(); | ||
mInited = false; | ||
} | ||
|
||
protected void onInited() {} | ||
|
||
protected void onSuspended() {} | ||
|
||
public final boolean isInited() { | ||
return mInited; | ||
} | ||
|
||
protected abstract UC createUiCallbacks(U ui); | ||
|
||
public synchronized final void attachUi(U ui) { | ||
Preconditions.checkArgument(ui != null, "ui cannot be null"); | ||
Preconditions.checkState(!mUis.contains(ui), "UI is already attached"); | ||
mUis.add(ui); | ||
ui.setCallbacks(createUiCallbacks(ui)); | ||
} | ||
|
||
public synchronized final void startUi(U ui) { | ||
Preconditions.checkArgument(ui != null, "ui cannot be null"); | ||
Preconditions.checkState(mUis.contains(ui), "ui is not attached"); | ||
populateUi(ui); | ||
} | ||
|
||
public synchronized final void detachUi(U ui) { | ||
Preconditions.checkArgument(ui != null, "ui cannot be null"); | ||
Preconditions.checkState(mUis.contains(ui), "ui is not attached"); | ||
ui.setCallbacks(null); | ||
mUis.remove(ui); | ||
} | ||
|
||
protected synchronized void populateUi(U ui) {} | ||
|
||
protected synchronized final void populateUis() { | ||
if (AppConfig.DEBUG) { | ||
Log.d(getClass().getSimpleName(), "populateUis"); | ||
} | ||
for (U ui : mUis) { | ||
populateUi(ui); | ||
} | ||
} | ||
|
||
protected final Set<U> getUis() { | ||
return mUnmodifiableUis; | ||
} | ||
|
||
protected int getId(U ui) { | ||
return ui.hashCode(); | ||
} | ||
|
||
protected synchronized U findUi(final int id) { | ||
for (U ui : mUis) { | ||
if (getId(ui) == id) { | ||
return ui; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public void setDisplay(Display display) { | ||
mDisplay = display; | ||
} | ||
|
||
public final Display getDisplay() { | ||
return mDisplay; | ||
} | ||
|
||
public interface Ui<UC> { | ||
void setCallbacks(UC callbacks); | ||
|
||
UC getCallbacks(); | ||
|
||
void onResponseError(ResponseError error); | ||
} | ||
|
||
public interface ListUi<T, UC> extends Ui<UC> { | ||
void onStartRequest(int page); | ||
|
||
void onFinishRequest(List<T> items, int page, boolean haveNextPage); | ||
} | ||
|
||
public interface SubUi {} | ||
} |
162 changes: 162 additions & 0 deletions
162
app/src/main/java/com/cheikh/lazywaimai/base/BaseFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package com.cheikh.lazywaimai.base; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.annotation.StringRes; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v7.app.ActionBar; | ||
import android.support.v7.widget.Toolbar; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import butterknife.Bind; | ||
import butterknife.ButterKnife; | ||
import com.cheikh.lazywaimai.R; | ||
import com.cheikh.lazywaimai.model.bean.ResponseError; | ||
import com.cheikh.lazywaimai.util.ContentView; | ||
import com.cheikh.lazywaimai.ui.Display; | ||
import com.cheikh.lazywaimai.widget.LoadingDialog; | ||
|
||
/** | ||
* author: cheikh.wang on 16/11/23 | ||
* email: [email protected] | ||
*/ | ||
public abstract class BaseFragment<UC> extends Fragment | ||
implements BaseController.Ui<UC> { | ||
|
||
@Nullable | ||
@Bind(R.id.toolbar) | ||
Toolbar mToolbar; | ||
|
||
private UC mCallbacks; | ||
|
||
private LoadingDialog mLoading; | ||
|
||
@Override | ||
public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
return inflater.inflate(getLayoutResId(), container, false); | ||
} | ||
|
||
@Override | ||
public final void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
ButterKnife.bind(this, view); | ||
initialToolbar(); | ||
handleArguments(getArguments()); | ||
initialViews(savedInstanceState); | ||
} | ||
|
||
@Override | ||
public void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
getController().attachUi(this); | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
getController().startUi(this); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
getController().detachUi(this); | ||
} | ||
|
||
protected int getLayoutResId() { | ||
for (Class c = getClass(); c != Fragment.class; c = c.getSuperclass()) { | ||
ContentView annotation = (ContentView) c.getAnnotation(ContentView.class); | ||
if (annotation != null) { | ||
return annotation.value(); | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
protected void initialToolbar() { | ||
if (mToolbar != null) { | ||
mToolbar.setTitle(getTitle()); | ||
setSupportActionBar(mToolbar); | ||
if (isShowBack()) { | ||
getSupportActionBar().setHomeButtonEnabled(true); | ||
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||
} | ||
} | ||
} | ||
|
||
protected void handleArguments(Bundle arguments) {} | ||
|
||
protected void initialViews(Bundle savedInstanceState) {} | ||
|
||
@Override | ||
public UC getCallbacks() { | ||
return mCallbacks; | ||
} | ||
|
||
@Override | ||
public void setCallbacks(UC callbacks) { | ||
mCallbacks = callbacks; | ||
} | ||
|
||
@Override | ||
public void onResponseError(ResponseError error) {} | ||
|
||
protected abstract BaseController getController(); | ||
|
||
protected Display getDisplay() { | ||
return ((BaseActivity) getActivity()).getDisplay(); | ||
} | ||
|
||
protected Toolbar getToolbar() { | ||
return mToolbar; | ||
} | ||
|
||
protected String getTitle() { | ||
return null; | ||
} | ||
|
||
protected boolean isShowBack() { | ||
return true; | ||
} | ||
|
||
protected void setTitle(CharSequence title) { | ||
if (mToolbar != null) { | ||
mToolbar.setTitle(title); | ||
} | ||
} | ||
|
||
protected void setTitle(@StringRes int titleRes) { | ||
if (mToolbar != null) { | ||
mToolbar.setTitle(titleRes); | ||
} | ||
} | ||
|
||
protected void setSupportActionBar(Toolbar toolbar) { | ||
((BaseActivity) getActivity()).setSupportActionBar(toolbar); | ||
} | ||
|
||
protected ActionBar getSupportActionBar() { | ||
return ((BaseActivity) getActivity()).getSupportActionBar(); | ||
} | ||
|
||
protected final void showLoading(@StringRes int textResId) { | ||
showLoading(getString(textResId)); | ||
} | ||
|
||
protected final void showLoading(String text) { | ||
cancelLoading(); | ||
if (mLoading == null) { | ||
mLoading = new LoadingDialog(getContext()); | ||
mLoading.setCancelable(false); | ||
mLoading.setCanceledOnTouchOutside(false); | ||
} | ||
mLoading.setTitle(text); | ||
mLoading.show(); | ||
} | ||
|
||
protected final void cancelLoading() { | ||
if (mLoading != null && mLoading.isShowing()) { | ||
mLoading.dismiss(); | ||
} | ||
} | ||
} |
Oops, something went wrong.