EExcel 丞燕快速查詢2

EExcel 丞燕快速查詢2
EExcel 丞燕快速查詢2 https://sandk.ffbizs.com/

[轉]Couchbase Lite stops syncing when an app resumes from background

http://stackoverflow.com/questions/20822285/couchbase-lite-stops-syncing-when-an-app-resumes-from-background



answered Dec 30 '13 at 12:55

MonkeyBonkey


Looks like if I set the replication to "persistent" it resumes on app backgrounding

e.g._pull.persistent = YES;

couchbase todolist get database sync part

https://github.com/couchbaselabs/ToDoLite-Android


 Write ToDoLite database sync  guy  is very good.

OK, take out.

android studio:new project   then


  • Copy todolist four java :

             Application.java、BaseActivity.java、Preferences.java、Synchronize.java


  • Edit  java : MainActivityjava、AndroidManifes.xml 

           1、app/src/main/AndroidManifest.xml
            <application 
     add        android:name="com.sandk.groupaccountbook.Application"


           2、app/src/main/java/com/sandk/groupaccountbook/MainActivity.java
  change     public class MainActivity extends ActionBarActivity  => 
                  public class MainActivity extends BaseActivity {


If have new activity, just change extends to BaseActivity, then can use application.getDatabase().

four java : any use facebook just // or delete

now database = application.getDatabase()  is ok~~

==========
主要是新增四支java和二個設定

從todolist copy 四支為:
Application.java、BaseActivity.java、Preferences.java、Synchronize.java 

變更設定為:MainActivityjava、AndroidManifes.xml 

差別閱github版本差異 官方寫的非常漂亮,可以切開來

  • app/src/main/AndroidManifest.xml
            <application 
     add        android:name="com.sandk.groupaccountbook.Application"


  • app/src/main/java/com/sandk/groupaccountbook/MainActivity.java
  change     public class MainActivity extends ActionBarActivity  => 
                  public class MainActivity extends BaseActivity {

別忘記最重要的, MainActivity extends 要改成 BaseActivity
將來有新的Activity extends BaseActivity 就行用了!


把四支新增 java,裡面有facebook 部份註解掉,基本上就能使用了


寫程式就可以用 database = application.getDatabase()


android & couchbase app -- ok, now can share little

1. activity_main.xml   =>   tools:context=".MainActivity"  => MainActivity.java


.......I try first... is more better  then post.

=========
=========
===== suggestion newbie =====
https://github.com/couchbaselabs/CouchbaseLite-DevDay-StarterKit
https://github.com/couchbaselabs/GrocerySync-Android
https://github.com/couchbaselabs/ToDoLite-Android        (Hard Understand) SO see this first:
http://sueboy.blogspot.com/2015/06/couchbase-todolist-get-database-sync.html
=========

MainActivity.java

  BuildConfig -- 來自 build.gradle ( Module.app ) 目錄app -- build.gradle

  extends ActionBarActivity -- http://blog.tonycube.com/2014/02/android-actionbarcompat-1.html

  Intent -- http://www.imyukin.com/?p=183
         -- http://kezeodsnx.pixnet.net/blog/post/27072894-android-----%E6%87%89%E7%94%A8%E7%A8%8B%E5%BC%8F%E8%87%AA%E6%88%91%E4%BB%8B%E7%B4%B9%E4%B9%8Bintent-resolution

  startService -- http://blog.maxkit.com.tw/2014/01/android-serviceintentservice.html
               -- http://blog.kenyang.net/2012/11/android-startservice-vs-bindservice.html
               -- http://blog.csdn.net/biezhihua/article/details/44439897
    context.bindService() <==> context.startService()
    context.startService() ==> Service <==> IntentService

  AsyncTask -- http://a-can.logdown.com/blog/201623/android-asynctask-asynchronous-functions-are-carefully

  Observer -- http://www.apkbus.com/android-112815-1-1.html

  runOnUiThread -- http://lak4cyut.blogspot.com/2011/03/android-tip-activityrunonuithread.html
                -- http://blog.csdn.net/zhang_yanye/article/details/40794629

  getApplication Application.java -- http://www.cnblogs.com/duanxz/p/4379800.html

  Replication 同步local到remote -- http://developer.couchbase.com/mobile/develop/references/couchbase-lite/couchbase-lite/replication/index.html

  application.getOnSyncProgressChangeObservable() --
    onSyncProgressChangeObservable --
      addObserver -- http://www.apkbus.com/android-112815-1-1.html

  application.getOnSyncUnauthorizedObservable().addObserver(new Observer()

  application.startReplicationSyncWithCustomCookie 開始同步到remote

  DrawerLayout -- http://ikevin.tw/?p=277


===== command see database =====
http://xxxx.xxxx.com:4985/_admin
http://xxxx.xxxx.com:4985/groupaccountingbooks/_session
http://xxxx.xxxx.com:4985/groupaccountingbooks/_user/
http://xxxx.xxxx.com:4985/groupaccountingbooks/_persona
http://xxxx.xxxx.com:4985/groupaccountingbooks/_changes
http://xxxx.xxxx.com:4985/groupaccountingbooks/_all_docs

open Sync Gateway GUEST account
http://xxxx.xxxx.com:4985/default/_user/GUEST --data  '{"disabled":false, "admin_channels":["public"]}

add sync_gateway user (basic auth : user must exist on Sync Gateway.)
https://forums.couchbase.com/t/couchbase-lite-and-couchbase-sync-gate-way-authentication-failed/3993
https://forums.couchbase.com/t/user-authentication-document-best-practices/3086
http://sueboy.blogspot.com/2015/06/couchbase-basic-auth-basicauth.html
==========

===== couchbase todolist =====

getDeviceToken  ==> AsyncTask ==> doInBackground ==> GoogleCloudMessaging gcm

Synchronize.java <== Application.java <== Many use


===== android adapter view listen best way =====
http://androidadapternotifiydatasetchanged.blogspot.com/2013/02/android-notifydatasetchanged.html
http://stackoverflow.com/questions/4198425/updating-the-list-view-when-the-adapter-data-changes
https://developer.android.com/training/material/lists-cards.html

===== RecyclerView  =====
http://blog.csdn.net/guxiao1201/article/details/40423361
http://hmkcode.com/android-simple-recyclerview-widget-example/
http://blog.csdn.net/li396858359/article/details/40270921
http://www.eoeandroid.com/thread-535701-1-1.html
https://blog.nraboy.com/2015/04/create-a-couchbase-lite-todo-list-with-native-android/


===== RecyclerView onClick =====
http://stackoverflow.com/questions/24885223/why-doesnt-recyclerview-have-onitemclicklistener-and-how-recyclerview-is-dif
http://sueboy.blogspot.com/2015/06/recyclerview-onclick.html


===== Write your own Android Sync Adapter =====
http://blog.udinic.com/2013/07/24/write-your-own-android-sync-adapter/


==== Easy start new activity on button click =====
http://stackoverflow.com/questions/4186021/how-to-start-new-activity-on-button-click


===== How to add Secure Sync to your mobile apps =====
https://github.com/couchbaselabs/sg-live-demo


=====  save document =====
Map<String, Object> properties = new HashMap<String, Object>();
properties.put["type", "List"];
properties.put["title", title];
properties.put["created_at", currentTimeString];
properties.put["owner", "profile:"+ userId];
properties.put["members",, new ArrayList<String>()];

//save to database
Document document = database.cretaeDocument();
document.putProperties(properties);


===== read document =====
Document document = database.getDocumnet(mDocId);
String title = document.getProperty("title");

Map<String, Objectt> properties = doc.getProperties();
String owner = (String) properties.get("owner");


===== Push Pull =====
Push => Server or couchbase SyncGateway
Pull <= Server or couchbase SyncGateway


===== cookie auth =====
app calls my server which POST to SyncGateway's _session
https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/mobile-couchbase/83srQTNmXj0/sPOW61ZWNtkJ



couchbase basic auth basicAuth startReplicationSyncWithBasicAuth --- How To Do

突然想到,他的basic auth,其實不是用來給系統用的,是給app用的
也就是app每一支都是用同樣的basicAuth id/pwd登入,區分 管理者和一般使用者

而一般使用者註冊後,帳密是另外開一個doucment,之後所有的文件管理是自己要控制的
跟mysql的一樣,不會給每個人有basic auth,權限管理,也是在sql下的時候,抓出資料做判斷

所以才會在 add user時,用restful curd,使用者代表不同的專案

==========
This is my think:

couchbase basic auth is not for every body login. It is app connect to sync_gateway for auth. Example is have normal user and Admin user. Maybe login sync_gateway, that get different document、channel、sync.

Normal user registered. The register data put in document, Maybe document name is "members" then system programmer need to control document show or not by permit. Like sql not everybody register, then get login mysql account. Only one account connect. After login, everythings is by program control.

So add user is use restful curd to sync_gateway. Like different project <= user.


 (basic auth : user must exist on Sync Gateway.)
https://forums.couchbase.com/t/couchbase-lite-and-couchbase-sync-gate-way-authentication-failed/3993
https://forums.couchbase.com/t/user-authentication-document-best-practices/3086

==========

curl -vX     POST
-H     'Content-Type: application/json'
-d     '{"name": "guest",   "password": "xxxooo"}'
http://xxx.xxx.com:4985/db_name xxx ooo/_user/

use method POST
db_name xxx ooo is your db name



==========
when user login use basic auth website  (If sync_gateway guest disable)

http://sandk.mkinweb.com:4984/groupaccountingbooks/    This is login, you need to login by aa : aaa
http://sandk.mkinweb.com:4984/groupaccountingbooks/_session   If login ok, you can see this have

{"authentication_handlers":["default","cookie"],"ok":true,"userCtx":{"channels":{"!":1},"name":"aa"}}


==========
See best new couchbase android todolite
ok~ see java    ui.login/LoginActivity

mBasicAuthButton = (Button)findViewById(R.id.basicAuthLoginButton);
then see layout : activity_login.xml   ok,find this:
android:id="@+id/basicAuthLoginButton"  

then you see 
android:visibility="invisible" />  just remove  "invisible".  When you login,  now you can see button.

But click no anythings.  Ok~ go back  ui.login/LoginActivity  find this:
private void promptUserForBasicAuthAndStartSync() {

see commit, now you can understand.  add user / pwd

curl -X POST http://localhost:4985/${db}/_user/ -d '{"name":"foo", "password":"bar"}'


For Session

key point:  create one session
curl -X POST -H "Content-type: application/json" -d '{"name": "your-user-id"}' localhost:4985/todolite/_session

then sync_getway renturn session_id

{"session_id":"03bdd7f1be83f035a7298924f9a28270feac7f4c","expires":"2015-03-17T21:39:16.076186179Z","cookie_name":"SyncGatewaySession"}

then chang session_id to 
private void loginWithCustomCookieAndStartSync() {



==========
sync_gate have username, password , this username, password for couchbae server, new bucket setting username, password

{
  "log": ["CRUD", "REST+", "Access"],
  "interface":":4984",
  "adminInterface":"192.168.0.00:4985",
  "databases": {
     "groupaccountingbooks": {
       "username": "xxxxoooo",
       "password": "xxxxoooo",

       "server": "http://192.168.0.00:8091/",
       "users": {
          "GUEST": {"disabled": true, "admin_channels": ["*"] }
        },
        "sync": function(doc, oldDoc) { channel("all_docs"); }
      }
    }
}


graphical http client restful

https://code.google.com/p/im-only-resting/
http://www.swensensoftware.com/im-only-resting


https://github.com/wiztools/rest-client


RecyclerView onclick

RecyclerView step 3

step1
public class xxxxxxxx extends RecyclerView.Adapter<MyAdapter.ViewHolder> implements View.OnClickListener {



step2

public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position
viewHolder.textView.setOnClickListener(this);

textView is findViewById(R.id.xxxxxxxxx)


step3


@Override
public void onClick(View view) {
  int viewId = view.getId();
   if (viewId == R.id.xxxxxxxxx) {  //which item click
      if (onItemClickListener != null) {
         onItemClickListener.onItemClick(view, (Integer) view.getTag());
      }
  }
}



view.getTag() maybe null

about RecyclerView error: android.widget.LinearLayout cannot be cast to android.widget.TextView

https://developer.android.com/training/material/lists-cards.html


I think many people, try to do this demo. But this demo is not good, because some things no show.
like:

RecyclerView .xml to a layout:.......only little, but ok, this not import.
MyAdapter .xml no layout: this is bad. Get error in here.

so, follow this do is better
http://stackoverflow.com/questions/28407768/android-widget-linearlayout-cannot-be-cast-to-android-widget-textview-in-recycle

Gorcyn  is good guy~~ ^ ^

But what different with android demo (fxxxxxxxxxxxxxx)

android:
  • public ViewHolder(TextView v) {
  • mTextView = v;

good guy:
  • public ViewHolder(View v) {
  • mTextView = v.findViewById(R.id.textView));

so Now I think you understand what happen, if you lean java.

Why android developer not put full demo, than everybody get right demo. I search this issue, wast 3 hours. And on internet many people get this problem. Really miss Delphi~~

write java let me feel back ten years ago. that time write can use jbuilder 2. But now ...........

powerbuilder is good for demo, too.