Search in sources :

Example 1 with PresetStoreAdapter

use of com.bedrock.padder.adapter.PresetStoreAdapter in project Tapad by berict.

the class PresetStoreActivity method setAdapter.

private void setAdapter() {
    Log.d(TAG, "setAdapter");
    // attach the adapter to the layout
    if (new File(metadataLocation).exists()) {
        // metadata file exists
        String metadata = fileHelper.getStringFromFile(metadataLocation);
        if (isFirebaseMetadataUpdated(activity)) {
            // updated, download new one
            downloadMetadata();
        } else {
            Log.d(TAG, "Attached adapter");
            // offline or not updated, continue
            Gson gson = new Gson();
            FirebaseMetadata firebaseMetadata = gson.fromJson(metadata, FirebaseMetadata.class);
            if (firebaseMetadata == null || firebaseMetadata.getPresets() == null || firebaseMetadata.getVersionCode() == null) {
                // corrupted metadata, download again
                downloadMetadata();
            } else {
                // attach adapter while its not null
                presetStoreAdapter = new PresetStoreAdapter(firebaseMetadata, R.layout.adapter_preset_store, activity);
                window.getRecyclerView(R.id.layout_preset_store_recyclerview, activity).setAdapter(presetStoreAdapter);
            }
            setLoadingFinished(true);
        }
    } else {
        downloadMetadata();
    }
}
Also used : PresetStoreAdapter(com.bedrock.padder.adapter.PresetStoreAdapter) FirebaseMetadata(com.bedrock.padder.model.FirebaseMetadata) Gson(com.google.gson.Gson) File(java.io.File)

Aggregations

PresetStoreAdapter (com.bedrock.padder.adapter.PresetStoreAdapter)1 FirebaseMetadata (com.bedrock.padder.model.FirebaseMetadata)1 Gson (com.google.gson.Gson)1 File (java.io.File)1