Search in sources :

Example 1 with FirebaseMetadata

use of com.bedrock.padder.model.FirebaseMetadata 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)

Example 2 with FirebaseMetadata

use of com.bedrock.padder.model.FirebaseMetadata in project Tapad by berict.

the class MainActivity method makeJson.

private void makeJson() {
    Item[] fadedItems = { new Item("facebook", w.getStringFromId("preset_faded_detail_facebook", a)), new Item("twitter", w.getStringFromId("preset_faded_detail_twitter", a)), new Item("soundcloud", w.getStringFromId("preset_faded_detail_soundcloud", a)), new Item("instagram", w.getStringFromId("preset_faded_detail_instagram", a)), new Item("google_plus", w.getStringFromId("preset_faded_detail_google_plus", a)), new Item("youtube", w.getStringFromId("preset_faded_detail_youtube", a)), //new Item("twitch", w.getStringFromId("preset_faded_detail_twitch", a)), // only omfg
    new Item("web", w.getStringFromId("preset_faded_detail_web", a)) };
    Detail fadedDetail = new Detail(w.getStringFromId("preset_faded_detail_title", a), fadedItems);
    Item[] fadedSongItems = { new Item("soundcloud", w.getStringFromId("preset_faded_song_detail_soundcloud", a), false), new Item("youtube", w.getStringFromId("preset_faded_song_detail_youtube", a), false), new Item("spotify", w.getStringFromId("preset_faded_song_detail_spotify", a), false), new Item("google_play_music", w.getStringFromId("preset_faded_song_detail_google_play_music", a), false), new Item("apple", w.getStringFromId("preset_faded_song_detail_apple", a), false), new Item("amazon", w.getStringFromId("preset_faded_song_detail_amazon", a), false), new Item("pandora", w.getStringFromId("preset_faded_song_detail_pandora", a), false) };
    Detail fadedSongDetail = new Detail(w.getStringFromId("preset_faded_song_detail_title", a), fadedSongItems);
    Bio fadedBio = new Bio(w.getStringFromId("preset_faded_bio_title", a), "alan_walker_faded_gesture", w.getStringFromId("preset_faded_bio_name", a), w.getStringFromId("preset_faded_bio_text", a), w.getStringFromId("preset_faded_bio_source", a));
    Detail[] fadedDetails = { fadedDetail, fadedSongDetail };
    About fadedAbout = new About(w.getStringFromId("preset_faded_title", a), "alan_walker_faded_gesture", w.getStringFromId("preset_faded_tutorial_link", a), "Studio Berict", "#00D3BE", fadedBio, fadedDetails);
    Music fadedMusic = new Music("preset_faded", "alan_walker_faded_gesture", true, 246, 90, null);
    Preset fadedPreset = new Preset("alan_walker_faded_gesture", fadedMusic, fadedAbout);
    largeLog("JSON", gson.toJson(fadedPreset));
    Preset[] presets = { fadedPreset };
    FirebaseMetadata firebaseMetadata = new FirebaseMetadata(presets, 15);
    largeLog("Metadata", gson.toJson(firebaseMetadata));
//        Bio tapadBio = new Bio(
//                w.getStringFromId("info_tapad_bio_title", a),
//                "about_bio_tapad",
//                w.getStringFromId("info_tapad_bio_name", a),
//                w.getStringFromId("info_tapad_bio_text", a),
//                w.getStringFromId("info_tapad_bio_source", a)
//        );
//
//        Item tapadInfo[] = {
//                new Item("info_tapad_info_check_update", w.getStringFromId("info_tapad_info_check_update_hint", a), "google_play", true),
//                new Item("info_tapad_info_tester", w.getStringFromId("info_tapad_info_tester_hint", a), "experiment", true),
//                new Item("info_tapad_info_legal", null, "info", false),
//                new Item("info_tapad_info_version", w.getStringFromId("info_tapad_info_version_hint", a), ""),
//                new Item("info_tapad_info_build_date", w.getStringFromId("info_tapad_info_build_date_hint", a), ""),
//                new Item("info_tapad_info_changelog", null, "changelog", false),
//                new Item("info_tapad_info_thanks", null, "thanks", false),
//                new Item("info_tapad_info_dev", w.getStringFromId("info_tapad_info_dev_hint", a), "developer", false)
//                // TODO ADD ITEMS
//        };
//
//        Item tapadOthers[] = {
//                new Item("info_tapad_others_song", w.getStringFromId("info_tapad_others_song_hint", a), "song", true),
//                new Item("info_tapad_others_feedback", w.getStringFromId("info_tapad_others_feedback_hint", a), "feedback", true),
//                new Item("info_tapad_others_report_bug", w.getStringFromId("info_tapad_others_report_bug_hint", a), "report_bug", true),
//                new Item("info_tapad_others_rate", w.getStringFromId("info_tapad_others_rate_hint", a), "rate", true),
//                new Item("info_tapad_others_translate", w.getStringFromId("info_tapad_others_translate_hint", a), "web", false),
//                new Item("info_tapad_others_recommend", w.getStringFromId("info_tapad_others_recommend_hint", a), "recommend", true)
//        };
//
//        Detail tapadDetails[] = {
//                new Detail(w.getStringFromId("info_tapad_info_title", a), tapadInfo),
//                new Detail(w.getStringFromId("info_tapad_others_title", a), tapadOthers)
//        };
//
//        About tapadAbout = new About(
//                w.getStringFromId("info_tapad_title", a),
//                "about_image_tapad",
//                "#9C27B0",
//                tapadBio, tapadDetails
//        );
//
//        largeLog("tapadAboutJSON", gson.toJson(tapadAbout));
//
//        Bio berictBio = new Bio(
//                w.getStringFromId("info_berict_bio_title", a),
//                null,
//                w.getStringFromId("info_berict_bio_name", a),
//                w.getStringFromId("info_berict_bio_text", a),
//                w.getStringFromId("info_berict_bio_source", a)
//        );
//
//        Item devItems[] = {
//                new Item("facebook", w.getStringFromId("info_berict_detail_facebook", a)),
//                new Item("twitter", w.getStringFromId("info_berict_detail_twitter", a)),
//                new Item("google_plus", w.getStringFromId("info_berict_detail_google_plus", a)),
//                new Item("youtube", w.getStringFromId("info_berict_detail_youtube", a)),
//                new Item("discord", w.getStringFromId("info_berict_detail_discord", a)),
//                new Item("web", w.getStringFromId("info_berict_detail_web", a))
//        };
//
//        Item devSupport[] = {
//                new Item("info_berict_action_report_bug", w.getStringFromId("info_berict_action_report_bug_hint", a), "report_bug", true),
//                new Item("info_berict_action_rate", w.getStringFromId("info_berict_action_rate_hint", a), "rate", true),
//                new Item("info_berict_action_translate", w.getStringFromId("info_berict_action_translate_hint", a), "translate", false),
//                new Item("info_berict_action_donate", w.getStringFromId("info_berict_action_donate_hint", a), "donate", false)
//        };
//
//        Detail berictDetails[] = {
//                new Detail(w.getStringFromId("info_berict_detail_title", a), devItems),
//                new Detail(w.getStringFromId("info_berict_action_title", a), devSupport)
//        };
//
//        About berictAbout = new About(
//                w.getStringFromId("info_berict_title", a),
//                "about_image_berict",
//                "#607D8B",
//                berictBio, berictDetails
//        );
//
//        largeLog("berictAboutJSON", gson.toJson(berictAbout));
}
Also used : Item(com.bedrock.padder.model.about.Item) MenuItem(android.view.MenuItem) FirebaseMetadata(com.bedrock.padder.model.FirebaseMetadata) Music(com.bedrock.padder.model.preset.Music) Preset(com.bedrock.padder.model.preset.Preset) Bio(com.bedrock.padder.model.about.Bio) Detail(com.bedrock.padder.model.about.Detail) About(com.bedrock.padder.model.about.About)

Example 3 with FirebaseMetadata

use of com.bedrock.padder.model.FirebaseMetadata in project Tapad by berict.

the class FirebaseHelper method getFirebaseMetadata.

public FirebaseMetadata getFirebaseMetadata(Activity activity) {
    FileHelper fileHelper = new FileHelper();
    FirebaseApp.initializeApp(activity);
    String metadataLocation = PROJECT_LOCATION_PRESET_METADATA;
    StorageReference metadataReference = FirebaseStorage.getInstance().getReferenceFromUrl(FIREBASE_LOCATION_PRESETS_METADATA);
    if (new File(metadataLocation).exists()) {
        // metadata file exists
        String metadata = fileHelper.getStringFromFile(metadataLocation);
        if (getStorageMetadata(metadataReference, activity).getUpdatedTimeMillis() > new File(metadataLocation).lastModified()) {
            // updated, download new one
            return saveFirebaseMetadata(metadataReference, metadataLocation, activity);
        } else {
            // offline or not updated, continue
            Gson gson = new Gson();
            FirebaseMetadata firebaseMetadata = gson.fromJson(metadata, FirebaseMetadata.class);
            if (firebaseMetadata.getPresets() == null || firebaseMetadata.getVersionCode() == null) {
                // corrupted metadata, download again
                return saveFirebaseMetadata(metadataReference, metadataLocation, activity);
            } else {
                return firebaseMetadata;
            }
        }
    } else {
        return saveFirebaseMetadata(metadataReference, metadataLocation, activity);
    }
}
Also used : FirebaseMetadata(com.bedrock.padder.model.FirebaseMetadata) StorageReference(com.google.firebase.storage.StorageReference) Gson(com.google.gson.Gson) File(java.io.File)

Aggregations

FirebaseMetadata (com.bedrock.padder.model.FirebaseMetadata)3 Gson (com.google.gson.Gson)2 File (java.io.File)2 MenuItem (android.view.MenuItem)1 PresetStoreAdapter (com.bedrock.padder.adapter.PresetStoreAdapter)1 About (com.bedrock.padder.model.about.About)1 Bio (com.bedrock.padder.model.about.Bio)1 Detail (com.bedrock.padder.model.about.Detail)1 Item (com.bedrock.padder.model.about.Item)1 Music (com.bedrock.padder.model.preset.Music)1 Preset (com.bedrock.padder.model.preset.Preset)1 StorageReference (com.google.firebase.storage.StorageReference)1