今どきの Retrofit と LiveData で Coroutine

ありがとうございます。


👉 Retrofit 

ご存知の通り Retrofit2 では、サスペンドな関数も利用できるようになっております。

👉 SpaceX REST API で試す Retrofit の coroutine 対応 


// NewModel.kt
@GET("/feed/here/")
suspend fun getData(@Query("token") token : String) : Status


// NewRepository.kt
class Repository {
  var client = RetrofitService.createService(JsonApi::class.java)
  suspend fun getData(token : String) = client.getData(token)
}

ので、以下のようなこれまでのコードは、


// OldViewModel.kt
val data = MutableLiveData<Status>()

private fun loadData(token: String){
  viewModelScope.launch {
    val retrievedData = withContext(Dispatchers.IO) {
      repository.getData(token)
    }
    data.value = retrievedData
  }
}

シンプルに以下のように書けます。


// NewViewModel.kt
val data : LiveData<Status> = liveData(Dispatchers.IO) {
      val retrievedData = repository.getData(token)
      emit(retrievedData)
    }

ありがとうございます。

👉 Exploring new Coroutines and Lifecycle Architectural Components integration on Android 
👉 Using Retrofit 2 with Kotlin coroutines - ProAndroidDev 


Flipper で SQLite テーブルを直接見る

Stetho の Facebook が作成した Android / iOS どちらも使えるデバッグツールです。

👉 Open-sourcing Flipper: a new extensible debugging tool - Facebook Engineering 

👉 Flipper · Extensible mobile app debugging 

👉 facebook/flipper: A desktop debugging platform for mobile developers. 

We wanted to create a platform that gives us all the flexibility we need to build more advanced features and support for iOS. One of Flipper's core concepts is its extensibility using plugins. Plugins are written in React and we provide a set of ready-to-use UI components that allow developers to build great plugin UIs with a few lines of code.

iOSのより高度な機能とサポートを構築するために必要なすべての柔軟性を提供するプラットフォームを作成したかったのです。 Flipperのコアコンセプトの1つは、プラグインを使用した拡張性です。プラグインはReactで記述されており、開発者が数行のコードで優れたプラグインUIを構築できる、すぐに使用できるUIコンポーネントのセットを提供します。

👉 Stetho Guidance · Flipper 

dependencies、Application 内に記述しながら、セットアップ。


<activity android:name="com.facebook.flipper.android.diagnostics.FlipperDiagnosticActivity"
        android:exported="true"/>


repositories {
  jcenter()
}

dependencies {
  debugImplementation 'com.facebook.flipper:flipper:0.26.0'
  debugImplementation 'com.facebook.soloader:soloader:0.5.1'
  releaseImplementation 'com.facebook.flipper:flipper-noop:0.26.0'
}


public class MyApplication extends Application {

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, false);

    if (BuildConfig.DEBUG && FlipperUtils.shouldEnableFlipper(this)) {
      final FlipperClient client = AndroidFlipperClient.getInstance(this);
      client.addPlugin(new InspectorFlipperPlugin(this, DescriptorMapping.withDefaults()));
      client.start();
    }
  }
}

👉 Getting Started · Flipper 

ここでは Database プラグインを追加します。


client.addPlugin(new DatabasesFlipperPlugin(context));

👉 Databases Plugin Setup · Flipper 

あとは、PC上のデバッグクライアントを開くと直感的に参照できるようになります。

👉 android/architecture-samples at dagger-android 

使いやすいです。動作も軽快です。


res を複数作って機能・画面別にディレクトリ分けすると分かりやすい

👉 Split layouts into subfolders in Android Studio - ProAndroidDev 

以下のコードを見ながら。

👉 GitHub - android/architecture-samples at dagger-android 

コードは、画面別にディレクトリ分けしてるが、レイアウトファイルは、複雑なファイル名で res ディレクトリ直下に一緒くたに入ってる。

ここで、build.gradle で設定記述を追加する。


android {
  sourceSets {
    main {
      res.srcDirs = [
          'src/main/res',
          'src/main/res/layouts/tasks',
          'src/main/res/layouts/taskdetail',
          'src/main/res/layouts/addedittask',
          'src/main/res/layouts/statistics',
      ]
    }

こうすることで、レイアウトファイル群を画面別に分けることができる。

Android Studio はデフォルトで、一つのディレクトリのみ


android {
  sourceSets {
    main {
      res.srcDirs = [
          'src/main/res'
      ]

と等価な設定を持ってるので、それに、画面別ディレクトリを複数追加することで、Android Studio は、リソースファイルとして複数ディレクトリからファイルを読み込むことができるようになります。

あとは、それぞれのリソースファイルを振り分けて置くだけ。

以下、やってみた動画。



実際は、レイアウトファイルがもっと多くなるはずなので、分かりやすさはより顕著になる。

👉 Split layouts into subfolders in Android Studio - ProAndroidDev 


AndroidJUnit4.class is deprecated | androidx.test.InstrumentationRegistry is deprecated

地味にハマる。

こーゆーのは、いちいちググらないといけないのか?

誰の都合の変更だ?

以下、苦悩の動画。



ここら androidx.test.ext に注意していないと分からない。

👉 Google's Maven Repository 


dependencies {

    // …

    androidTestImplementation 'androidx.test:core:1.2.1-alpha02'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2-alpha02' // deprecated AndroidUnitTest4

そういういうことですか。

👉 android - AndroidJUnit4.class is deprecated: How to use androidx.test.ext.junit.runners.AndroidJUnit4? - Stack Overflow 
👉 android - androidx.test.InstrumentationRegistry is deprecated - Stack Overflow 


Related Categories :  AndroidappsDevelopmemtKotlin


そんな Camscanner の代替を探す

Googleが、人気のOCR機能付きPDF作成アプリ「CamScanner」にマルウェアが見つかったとして、これをGoogle Playストアから削除しました。CamScannerはこれまでに1億回以上もダウンロードされていました。

👉 Google Playでのダウンロード数が1億超のスキャナーアプリ「CamScanner」が悪意あるアプリに変貌 | カスペルスキー公式ブログ 

👉 見つかりませんでした 

Previously, a similar module was often found in preinstalled malware on Chinese-made smartphones. It can be assumed that the reason why this malware was added was the app developers’ partnership with an unscrupulous advertiser.

以前は、中国製のスマートフォンにプリインストールされたマルウェアで同様のモジュールがしばしば発見されました。 このマルウェアが追加された理由は、アプリ開発者と悪意のある広告主とのパートナーシップにあると考えられます。

👉 An advertising dropper in Google Play | Securelist 

CamScannerはウェブサイトでAdHubと呼ばれるサードパーティの広告SDKに悪意あるモジュールが含まれていたことを明らかにし、これを取り除いたバージョンを配布しています。しかし日本語のGoogle Playストアでは、記事執筆時点では2014年の古いバージョンが配布されています。

Google PlayStore で公開できていないようで、別の場所で apk を配布しています。

Dear CamScanner Android Users,

Our CamScanner Team has recently detected that the advertisement SDK provided by a third-party named AdHub, integrated in Android Version 5.11.7, has been reported for containing a malicious module that produces unauthorized advertising clicks.
Injection of any suspicious codes violates the CamScanner Security Policy! We will take immediate legal actions against Adhub! Fortunately, after rounds of security check, we have not found any evidence showing the module could cause any leak of document data.
We have removed all the ads SDKs not certified by Google Play and a new version would be released. Meanwhile, you may follow the steps HERE to update to the new version.
We would appreciate your patience and understanding.

CamScanner Androidユーザーの皆様、

CamScannerチームは最近、Androidバージョン5.11.7に統合されたAdHubというサードパーティが提供する広告SDKが、不正な広告クリックを生成する悪意のあるモジュールを含むと報告されたことを検出しました。
不審なコードを挿入すると、CamScannerセキュリティポリシーに違反します!Adhubに対して直ちに法的措置を講じます!幸いなことに、一連のセキュリティチェックの後、モジュールがドキュメントデータのリークを引き起こす可能性があることを示す証拠は見つかりませんでした。
Google Playで認定されていないすべての広告SDKを削除しました。新しいバージョンがリリースされます。その間、こちらの手順に従って新しいバージョンに更新することができます。
ご理解とご理解のほどよろしくお願いいたします。

👉 Detail 

1. Please tap HERE to upgrade with the latest Android version 5.12.5.

2. Since the apk is not from Google Play, you may receive system notices before downloading & installing the new version. It is okay to proceed further.

3. Maybe you are using the v5.12.5 updated from Google Play, then there is no action needed. You may check out your version in the CS app Settings -- Feedback -- About.
If you have any other problems, please feel free to contact us at asupport @ intsig.com. We will help you out ASAP.

1. ここをタップして、最新のAndroidバージョン5.12.5にアップグレードしてください。

2. apkはGoogle Playのものではないため、新しいバージョンをダウンロードしてインストールする前にシステム通知を受け取る場合があります。さらに先へ進んでも構いません。

3.たぶん、Google Playから更新されたv5.12.5を使用している場合、アクションは必要ありません。CSアプリの[設定]-[フィードバック]-[バージョン情報]でバージョンを確認できます。
他に問題がある場合は、asupport @ intsig.comまでお気軽にお問い合わせください。できるだけ早くお手伝いします。

downloadForGP-apk

👉 詳細 

きっと、その広告SDKが埋め込まれてない旧バーションは PlayStore にもあります。

👉 CamScanner HD - Scanner, Fax - Google Play のアプリ 

以下、代替アプリリンク集リンク。

👉 5 Free CamScanner Alternatives for Android 

👉 7 Alternatives to CamScanner | Product Hunt 

👉 10 Best CamScanner Alternatives for Android and iOS | Beebom 

思ったよりたくさんあったので驚きました。

代替はいくらでもあるのです!!