mirror of
https://github.com/leanote/leanote-android.git
synced 2025-10-19 17:14:22 +00:00
fetch notes when sign in; modify some text;
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
|
|
||||||
<activity android:name="org.houxg.leamonax.ui.LeaLaunchActivity">
|
<activity android:name="org.houxg.leamonax.ui.LaunchActivity">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
@@ -8,7 +8,7 @@ import org.houxg.leamonax.model.Account;
|
|||||||
import org.houxg.leamonax.network.ApiProvider;
|
import org.houxg.leamonax.network.ApiProvider;
|
||||||
import org.houxg.leamonax.service.AccountService;
|
import org.houxg.leamonax.service.AccountService;
|
||||||
|
|
||||||
public class LeaLaunchActivity extends Activity {
|
public class LaunchActivity extends Activity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -17,7 +17,7 @@ public class LeaLaunchActivity extends Activity {
|
|||||||
if (AccountService.isSignedIn()) {
|
if (AccountService.isSignedIn()) {
|
||||||
Account account = AccountService.getCurrent();
|
Account account = AccountService.getCurrent();
|
||||||
ApiProvider.getInstance().init(account.getHost());
|
ApiProvider.getInstance().init(account.getHost());
|
||||||
intent = new Intent(this, MainActivity.class);
|
intent = MainActivity.getOpenIntent(this, false);
|
||||||
} else {
|
} else {
|
||||||
intent = new Intent(this, SignInActivity.class);
|
intent = new Intent(this, SignInActivity.class);
|
||||||
}
|
}
|
@@ -87,7 +87,7 @@ public class MainActivity extends BaseActivity implements NotebookAdapter.Notebo
|
|||||||
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu_white);
|
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu_white);
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
mNoteFragment = NoteFragment.newInstance();
|
mNoteFragment = NoteFragment.newInstance(getIntent().getBooleanExtra(EXT_SHOULD_RELOAD, false));
|
||||||
getFragmentManager().beginTransaction().add(R.id.container, mNoteFragment, TAG_NOTE_FRAGMENT).commit();
|
getFragmentManager().beginTransaction().add(R.id.container, mNoteFragment, TAG_NOTE_FRAGMENT).commit();
|
||||||
} else {
|
} else {
|
||||||
mNoteFragment = (NoteFragment) getFragmentManager().findFragmentByTag(TAG_NOTE_FRAGMENT);
|
mNoteFragment = (NoteFragment) getFragmentManager().findFragmentByTag(TAG_NOTE_FRAGMENT);
|
||||||
|
@@ -32,6 +32,7 @@ import org.houxg.leamonax.model.Note;
|
|||||||
import org.houxg.leamonax.model.SyncEvent;
|
import org.houxg.leamonax.model.SyncEvent;
|
||||||
import org.houxg.leamonax.service.NoteService;
|
import org.houxg.leamonax.service.NoteService;
|
||||||
import org.houxg.leamonax.utils.DisplayUtils;
|
import org.houxg.leamonax.utils.DisplayUtils;
|
||||||
|
import org.houxg.leamonax.utils.NetworkUtils;
|
||||||
import org.houxg.leamonax.utils.ToastUtils;
|
import org.houxg.leamonax.utils.ToastUtils;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -48,6 +49,7 @@ public class NoteFragment extends Fragment implements NoteAdapter.NoteAdapterLis
|
|||||||
|
|
||||||
private static final String TAG = "NoteFragment";
|
private static final String TAG = "NoteFragment";
|
||||||
private static final String EXT_SCROLL_POSITION = "ext_scroll_position";
|
private static final String EXT_SCROLL_POSITION = "ext_scroll_position";
|
||||||
|
private static final String EXT_SHOULD_FETCH_NOTES = "ext_should_fetch_notes";
|
||||||
|
|
||||||
public static final int RECENT_NOTES = -1;
|
public static final int RECENT_NOTES = -1;
|
||||||
|
|
||||||
@@ -64,8 +66,12 @@ public class NoteFragment extends Fragment implements NoteAdapter.NoteAdapterLis
|
|||||||
public NoteFragment() {
|
public NoteFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NoteFragment newInstance() {
|
public static NoteFragment newInstance(boolean shouldFetchNotes) {
|
||||||
return new NoteFragment();
|
NoteFragment fragment = new NoteFragment();
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putBoolean(EXT_SHOULD_FETCH_NOTES, shouldFetchNotes);
|
||||||
|
fragment.setArguments(bundle);
|
||||||
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -87,8 +93,7 @@ public class NoteFragment extends Fragment implements NoteAdapter.NoteAdapterLis
|
|||||||
mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onRefresh() {
|
public void onRefresh() {
|
||||||
//TODO:check network
|
syncNotes();
|
||||||
NoteSyncService.startServiceForNote(getActivity());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -108,12 +113,30 @@ public class NoteFragment extends Fragment implements NoteAdapter.NoteAdapterLis
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void syncNotes() {
|
||||||
|
if (!NetworkUtils.isNetworkAvailable(getActivity())) {
|
||||||
|
ToastUtils.showNetworkUnavailable(getActivity());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NoteSyncService.startServiceForNote(getActivity());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
EventBus.getDefault().register(this);
|
EventBus.getDefault().register(this);
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
mAdapter.loadFromLocal();
|
mAdapter.loadFromLocal();
|
||||||
|
if (getArguments().getBoolean(EXT_SHOULD_FETCH_NOTES, false)) {
|
||||||
|
mSwipeRefresh.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Log.i(TAG, "fetch notes");
|
||||||
|
mSwipeRefresh.setRefreshing(true);
|
||||||
|
syncNotes();
|
||||||
|
}
|
||||||
|
}, 200);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mScrollPosition = savedInstanceState.getFloat(EXT_SCROLL_POSITION, 0);
|
mScrollPosition = savedInstanceState.getFloat(EXT_SCROLL_POSITION, 0);
|
||||||
@@ -149,10 +172,6 @@ public class NoteFragment extends Fragment implements NoteAdapter.NoteAdapterLis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadNoteWithTag(String tag) {
|
|
||||||
mAdapter.loadFromLocal();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClickNote(Note note) {
|
public void onClickNote(Note note) {
|
||||||
startActivity(NotePreviewActivity.getOpenIntent(getActivity(), note.getId()));
|
startActivity(NotePreviewActivity.getOpenIntent(getActivity(), note.getId()));
|
||||||
|
@@ -155,7 +155,7 @@ public class SignInActivity extends BaseActivity implements TextWatcher {
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
ToastUtils.show(SignInActivity.this, R.string.wron_email_or_password);
|
ToastUtils.show(SignInActivity.this, R.string.email_or_password_incorrect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
<string name="change_password_failed">Change password failed</string>
|
<string name="change_password_failed">Change password failed</string>
|
||||||
<string name="choose_notebook">Choose notebook</string>
|
<string name="choose_notebook">Choose notebook</string>
|
||||||
<string name="delete_note_failed">Delete note failed</string>
|
<string name="delete_note_failed">Delete note failed</string>
|
||||||
<string name="wron_email_or_password">Wrong email or password</string>
|
<string name="email_or_password_incorrect">Email or password is incorrect</string>
|
||||||
<string name="network_error">Network error</string>
|
<string name="network_error">Network error</string>
|
||||||
<string name="untitled">Untitled</string>
|
<string name="untitled">Untitled</string>
|
||||||
<string name="time_yesterday">Yesterday %s</string>
|
<string name="time_yesterday">Yesterday %s</string>
|
||||||
|
Reference in New Issue
Block a user