RXJava Android无法在发布模式下工作/签名APK

时间:2017-01-11 02:55:35

标签: java android autocomplete

我在我的Android应用程序中使用rxjava库。在模式调试中,我的应用程序正常工作,可以显示来自API的数据。

屏幕截图:http://imgur.com/a/fRT17

但是在生成签名apk后,我的应用程序无法显示来自API的数据,也不会在logcat中产生任何错误。

这是我的代码:

public class MainActivity extends AppCompatActivity {

private static final long DELAY_IN_MILLIS = 500;
private CompositeSubscription compositeSubscription = new CompositeSubscription();
private Subscription subscription;
private String lokasi ="kosong";
private String idLokasi = "kosong";
private LokasiData dataLokasi = new LokasiData();

private final String TAG = "BelajarRX";

private TextView txt;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fabric.with(this, new Answers());
    setContentView(R.layout.activity_main);
    String TAG = "onCreate";
    Log.d(TAG, "ok jalan");

    final AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autocomplete);
    lokasi2(autoCompleteTextView);
    Button btn = (Button) findViewById(R.id.btn);

    txt = (TextView) findViewById(R.id.idlokasi);
    btn.setOnClickListener(view -> {
        idLokasi = dataLokasi.getKey();
        lokasi = autoCompleteTextView.getText().toString();
        Toast.makeText(getApplicationContext(),
                "LOKASI: " + lokasi, Toast.LENGTH_LONG).show();
        txt.setText("lokasi: " + idLokasi);
    });
}


private void lokasi2(final AutoCompleteTextView autoCompleteTextView)
{
    EpusApi api = EpusFactory.createRetrofitService(EpusApi.class);
    Observable<LokasiModel> observable;
    observable = RxTextView.textChangeEvents(autoCompleteTextView)
            .debounce(DELAY_IN_MILLIS, TimeUnit.MILLISECONDS)
            .map(textViewTextChangeEvent -> {
                Log.d(TAG, "map s: " + textViewTextChangeEvent.text().toString());
                return textViewTextChangeEvent.text().toString();
            })
            .filter(s -> s.length() > 2)
            .observeOn(Schedulers.io())
            .onBackpressureDrop()
            .flatMap(new Func1<String, Observable<LokasiModel>>() {
                @Override
                public Observable<LokasiModel> call(String s) {
                    Log.d(TAG, "observable s: " + s);
                    return api.getDataLokasi(s);

                }
            })
            .observeOn(AndroidSchedulers.mainThread())
            .retry();

    subscription = observable
            .subscribe(new Observer<LokasiModel>() {
                @Override
                public void onCompleted() {
                    Log.d(TAG, "complete");
                }

                @Override
                public void onError(Throwable e) {
                    Log.d(TAG, "ERooorr");
                    e.printStackTrace();
                }

                @Override
                public void onNext(LokasiModel lokasiModel) {
                    Log.d(TAG, "onNext");
                    List<LokasiData> lokasiDatas = new ArrayList<>();
                    lokasiDatas.addAll(lokasiModel.getDataList());

                    Lokasi3Adapter itemsAdapter = new Lokasi3Adapter(MainActivity.this,
                            R.layout.activity_main, android.R.layout.simple_list_item_1,
                            lokasiDatas);


                    autoCompleteTextView.setAdapter(itemsAdapter);

                    String enteredText = autoCompleteTextView.getText().toString();
                    Log.d(TAG, "enteredText " + enteredText);
                    if(lokasiDatas.size() >=1 && enteredText.contains(lokasiDatas.get(0).getDesa())){
                        Log.d(TAG, "NILAI getDesa: " + lokasiDatas.get(0).getDesa());
                        Log.d(TAG, "NILAI getKey: " + lokasiDatas.get(0).getKey());

                        autoCompleteTextView.dismissDropDown();
                    } else {
                        autoCompleteTextView.showDropDown();
                    }

                    autoCompleteTextView.setOnItemClickListener((adapterView, view, i, l)-> {
                        Log.d(TAG, "posisi " + lokasiDatas.get(i).getKey());
                        updateView(lokasiDatas.get(i));
                    });
                }
            });

    compositeSubscription.add(subscription);
}

private void updateView(LokasiData lokasiData){
    dataLokasi = lokasiData;
    TextView txtCode = (TextView) findViewById(R.id.txt_code);
    TextView txtDesa = (TextView) findViewById(R.id.txt_desa);
    TextView txtKec = (TextView) findViewById(R.id.txt_kec);
    TextView txtKotakab = (TextView) findViewById(R.id.txt_kotakab);
    TextView txtProv = (TextView) findViewById(R.id.txt_prov);

    txtCode.setText("Kode desa: " + lokasiData.getKey());
    txtDesa.setText("Desa: \t" + lokasiData.getDesa());
    txtKec.setText("Kecamatan: " + lokasiData.getKec());
    txtKotakab.setText("Kab/Kota: " + lokasiData.getKotakab());
    txtProv.setText("Provinsi: " + lokasiData.getProvinsi());

}

    @Override
    protected void onDestroy() {
        super.onDestroy();
        compositeSubscription.unsubscribe();
    }
}

这是proguard文件:

##---------------Begin: proguard configuration for RxJava  ----------
-dontwarn sun.misc.**
-dontwarn rx.**

-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
    long producerIndex;
    long consumerIndex;
}
-keepclassmembers class
rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
    rx.internal.util.atomic.LinkedQueueNode producerNode;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
    rx.internal.util.atomic.LinkedQueueNode consumerNode;
}
##---------------End: proguard configuration for RxJava  --------

提前致谢

0 个答案:

没有答案