diff --git a/app/build.gradle b/app/build.gradle index 880d6f0f..0c95ebd6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -169,7 +169,7 @@ dependencies { implementation project(":agendacalendarview") implementation project(":cafebar") - implementation project(":material-about-library") + implementation "eu.szkolny:material-about-library:0534abf316" implementation project(":mhttp") implementation project(":nachos") //implementation project(":Navigation") diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java index 555bc3fd..e1541d54 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java @@ -21,7 +21,6 @@ import com.danielstone.materialaboutlibrary.items.MaterialAboutActionItem; import com.danielstone.materialaboutlibrary.items.MaterialAboutActionSwitchItem; import com.danielstone.materialaboutlibrary.items.MaterialAboutItem; import com.danielstone.materialaboutlibrary.items.MaterialAboutItemOnClickAction; -import com.danielstone.materialaboutlibrary.items.MaterialAboutProfileItem; import com.danielstone.materialaboutlibrary.items.MaterialAboutSwitchItem; import com.danielstone.materialaboutlibrary.items.MaterialAboutTitleItem; import com.danielstone.materialaboutlibrary.model.MaterialAboutCard; @@ -156,12 +155,12 @@ public class SettingsNewFragment extends MaterialAboutFragment { roundDrawable.setCircular(true); return roundDrawable;*/ } - private MaterialAboutProfileItem profileCardTitleItem; + private MaterialAboutTitleItem profileCardTitleItem; private ArrayList getProfileCard(boolean expandedOnly) { ArrayList items = new ArrayList<>(); if (!expandedOnly) { - profileCardTitleItem = new MaterialAboutProfileItem( + profileCardTitleItem = new MaterialAboutTitleItem( app.getProfile().getName(), app.getProfile().getSubname(), getProfileDrawable() @@ -267,20 +266,20 @@ public class SettingsNewFragment extends MaterialAboutFragment { else { items.add( - new MaterialAboutSwitchItem( - getString(R.string.settings_profile_sync_text), - getString(R.string.settings_profile_sync_subtext), - new IconicsDrawable(activity) + new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_profile_sync_text) + .subText(R.string.settings_profile_sync_subtext) + .icon(new IconicsDrawable(activity) .icon(CommunityMaterial.Icon.cmd_account_convert) .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) + .color(IconicsColor.colorInt(iconColor))) .setChecked(app.getProfile().getSyncEnabled()) - .setOnChangeAction(((isChecked, tag) -> { + .setOnCheckedChanged(((item, isChecked) -> { app.getProfile().setSyncEnabled(isChecked); app.profileSave(); return true; })) + .build() ); } @@ -300,20 +299,20 @@ public class SettingsNewFragment extends MaterialAboutFragment { Date today = Date.getToday(); if (today.month == 12 || today.month == 1) { items.add( - new MaterialAboutSwitchItem( - getString(R.string.settings_theme_snowfall_text), - getString(R.string.settings_theme_snowfall_subtext), - new IconicsDrawable(activity) + new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_theme_snowfall_text) + .subText(R.string.settings_theme_snowfall_subtext) + .icon(new IconicsDrawable(activity) .icon(CommunityMaterial.Icon2.cmd_snowflake) .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) + .color(IconicsColor.colorInt(iconColor))) .setChecked(app.getConfig().getUi().getSnowfall()) - .setOnChangeAction((isChecked, tag) -> { + .setOnCheckedChanged((item, isChecked) -> { app.getConfig().getUi().setSnowfall(isChecked); activity.recreate(); return true; }) + .build() ); } @@ -343,24 +342,24 @@ public class SettingsNewFragment extends MaterialAboutFragment { ); items.add( - new MaterialAboutSwitchItem( - getString(R.string.settings_theme_mini_drawer_text), - getString(R.string.settings_theme_mini_drawer_subtext), - new IconicsDrawable(activity) + new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_theme_mini_drawer_text) + .subText(R.string.settings_theme_mini_drawer_subtext) + .icon(new IconicsDrawable(activity) .icon(CommunityMaterial.Icon.cmd_dots_vertical) .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) - .setChecked(app.getConfig().getUi().getMiniMenuVisible()) - .setOnChangeAction((isChecked, tag) -> { - // 0,1 1 - // 0,0 0 - // 1,1 0 - // 1,0 1 - app.getConfig().getUi().setMiniMenuVisible(isChecked); - activity.getNavView().drawer.setMiniDrawerVisiblePortrait(isChecked); - return true; - }) + .color(IconicsColor.colorInt(iconColor))) + .setChecked(app.getConfig().getUi().getMiniMenuVisible()) + .setOnCheckedChanged((item, isChecked) -> { + // 0,1 1 + // 0,0 0 + // 1,1 0 + // 1,0 1 + app.getConfig().getUi().setMiniMenuVisible(isChecked); + activity.getNavView().drawer.setMiniDrawerVisiblePortrait(isChecked); + return true; + }) + .build() ); items.add(getMoreItem(() -> addCardItems(CARD_THEME, getThemeCard(true)))); @@ -496,19 +495,18 @@ public class SettingsNewFragment extends MaterialAboutFragment { ); items.add( - new MaterialAboutSwitchItem( - getString(R.string.settings_theme_open_drawer_on_back_pressed_text), - null, - new IconicsDrawable(activity) + new MaterialAboutSwitchItem.Builder( ) + .text(R.string.settings_theme_open_drawer_on_back_pressed_text) + .icon(new IconicsDrawable(activity) .icon(CommunityMaterial.Icon2.cmd_menu_open) .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) + .color(IconicsColor.colorInt(iconColor))) .setChecked(app.getConfig().getUi().getOpenDrawerOnBackPressed()) - .setOnChangeAction((isChecked, tag) -> { + .setOnCheckedChanged((item, isChecked) -> { app.getConfig().getUi().setOpenDrawerOnBackPressed(isChecked); return true; }) + .build() ); } return items; @@ -548,20 +546,20 @@ public class SettingsNewFragment extends MaterialAboutFragment { ); } private MaterialAboutItem getSyncCardWifiItem() { - return new MaterialAboutSwitchItem( - getString(R.string.settings_sync_wifi_text), - getString(R.string.settings_sync_wifi_subtext), - new IconicsDrawable(activity) + return new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_sync_wifi_text) + .subText(R.string.settings_sync_wifi_subtext) + .icon(new IconicsDrawable(activity) .icon(CommunityMaterial.Icon2.cmd_wifi_strength_2) .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) + .color(IconicsColor.colorInt(iconColor))) .setChecked(app.getConfig().getSync().getOnlyWifi()) - .setOnChangeAction((isChecked, tag) -> { + .setOnCheckedChanged((item, isChecked) -> { app.getConfig().getSync().setOnlyWifi(isChecked); SyncWorker.Companion.rescheduleNext(app); return true; - }); + }) + .build(); } private MaterialAboutActionSwitchItem syncCardIntervalItem; private MaterialAboutActionSwitchItem syncCardQuietHoursItem; @@ -569,14 +567,14 @@ public class SettingsNewFragment extends MaterialAboutFragment { ArrayList items = new ArrayList<>(); if (!expandedOnly) { - syncCardIntervalItem = new MaterialAboutActionSwitchItem( - getString(R.string.settings_sync_sync_interval_text), - getString(R.string.settings_sync_sync_interval_subtext_disabled), - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon.cmd_download_outline) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ); + syncCardIntervalItem = new MaterialAboutActionSwitchItem.Builder() + .text(R.string.settings_sync_sync_interval_text) + .subText(R.string.settings_sync_sync_interval_subtext_disabled) + .icon(new IconicsDrawable(activity) + .icon(CommunityMaterial.Icon.cmd_download_outline) + .size(IconicsSize.dp(iconSizeDp)) + .color(IconicsColor.colorInt(iconColor))) + .build(); syncCardIntervalItem.setSubTextChecked(getSyncCardIntervalSubText()); syncCardIntervalItem.setChecked(app.getConfig().getSync().getEnabled()); syncCardIntervalItem.setOnClickAction(() -> { @@ -625,7 +623,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { }) .show(); }); - syncCardIntervalItem.setOnChangeAction((isChecked, tag) -> { + syncCardIntervalItem.setOnCheckedChangedAction((item, isChecked) -> { if (isChecked && !app.getConfig().getSync().getEnabled()) { addCardItem(CARD_SYNC, 1, getSyncCardWifiItem()); } @@ -660,14 +658,14 @@ public class SettingsNewFragment extends MaterialAboutFragment { );*/ - syncCardQuietHoursItem = new MaterialAboutActionSwitchItem( - getString(R.string.settings_sync_quiet_hours_text), - getString(R.string.settings_sync_quiet_hours_subtext_disabled), - new IconicsDrawable(activity) + syncCardQuietHoursItem = new MaterialAboutActionSwitchItem.Builder() + .text(R.string.settings_sync_quiet_hours_text) + .subText(R.string.settings_sync_quiet_hours_subtext_disabled) + .icon(new IconicsDrawable(activity) .icon(CommunityMaterial.Icon.cmd_bell_sleep_outline) .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ); + .color(IconicsColor.colorInt(iconColor))) + .build(); syncCardQuietHoursItem.setChecked(app.getConfig().getSync().getQuietHoursEnabled()); syncCardQuietHoursItem.setSubTextChecked(getSyncCardQuietHoursSubText()); syncCardQuietHoursItem.setOnClickAction(() -> { @@ -707,7 +705,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { }) .show(); }); - syncCardQuietHoursItem.setOnChangeAction((isChecked, tag) -> { + syncCardQuietHoursItem.setOnCheckedChangedAction((item, isChecked) -> { app.getConfig().getSync().setQuietHoursEnabled(isChecked); if (isChecked && app.getConfig().getSync().getQuietHoursStart() == null) { app.getConfig().getSync().setQuietHoursStart(new Time(22, 30, 0)); @@ -752,20 +750,19 @@ public class SettingsNewFragment extends MaterialAboutFragment { );*/ items.add( - new MaterialAboutSwitchItem( - getString(R.string.settings_sync_updates_text), - null, - new IconicsDrawable(activity) + new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_sync_updates_text) + .icon(new IconicsDrawable(activity) .icon(CommunityMaterial.Icon.cmd_cellphone_arrow_down) .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) + .color(IconicsColor.colorInt(iconColor))) .setChecked(app.getConfig().getSync().getNotifyAboutUpdates()) - .setOnChangeAction((isChecked, tag) -> { + .setOnCheckedChanged((item, isChecked) -> { app.getConfig().getSync().setNotifyAboutUpdates(isChecked); UpdateWorker.Companion.rescheduleNext(app); return true; }) + .build() ); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { @@ -846,16 +843,15 @@ public class SettingsNewFragment extends MaterialAboutFragment { ); } private MaterialAboutItem getRegisterCardSharedEventsItem() { - return new MaterialAboutSwitchItem( - getString(R.string.settings_register_shared_events_text), - getString(R.string.settings_register_shared_events_subtext), - new IconicsDrawable(activity) + return new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_register_shared_events_text) + .subText(R.string.settings_register_shared_events_subtext) + .icon(new IconicsDrawable(activity) .icon(CommunityMaterial.Icon2.cmd_share_outline) .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) + .color(IconicsColor.colorInt(iconColor))) .setChecked(app.getProfile().getEnableSharedEvents()) - .setOnChangeAction((isChecked, tag) -> { + .setOnCheckedChanged((item, isChecked) -> { app.getProfile().setEnableSharedEvents(isChecked); app.profileSave(); if (isChecked) new MaterialDialog.Builder(activity) @@ -869,7 +865,8 @@ public class SettingsNewFragment extends MaterialAboutFragment { .positiveText(R.string.ok) .show(); return true; - }); + }) + .build(); } private MaterialAboutSwitchItem registerCardAllowRegistrationItem; @@ -895,16 +892,16 @@ public class SettingsNewFragment extends MaterialAboutFragment { .color(IconicsColor.colorInt(iconColor)) ).setOnClickAction(() -> new AttendanceConfigDialog(activity, false, null, null))); - registerCardAllowRegistrationItem = new MaterialAboutSwitchItem( - getString(R.string.settings_register_allow_registration_text), - getString(R.string.settings_register_allow_registration_subtext), - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon.cmd_account_circle_outline) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ); + registerCardAllowRegistrationItem = new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_register_allow_registration_text) + .subText(R.string.settings_register_allow_registration_subtext) + .icon(new IconicsDrawable(activity) + .icon(CommunityMaterial.Icon.cmd_account_circle_outline) + .size(IconicsSize.dp(iconSizeDp)) + .color(IconicsColor.colorInt(iconColor))) + .build(); registerCardAllowRegistrationItem.setChecked(app.getProfile().getRegistration() == REGISTRATION_ENABLED); - registerCardAllowRegistrationItem.setOnChangeAction((isChecked, tag) -> { + registerCardAllowRegistrationItem.setOnCheckedChangedAction((item, isChecked) -> { if (isChecked) new MaterialDialog.Builder(activity) .title(getString(R.string.settings_register_allow_registration_dialog_enabled_title)) .content(getString(R.string.settings_register_allow_registration_dialog_enabled_text)) @@ -1025,55 +1022,53 @@ public class SettingsNewFragment extends MaterialAboutFragment { items.add(registerCardBellSyncItem); items.add( - new MaterialAboutSwitchItem( - getString(R.string.settings_register_count_in_seconds_text), - getString(R.string.settings_register_count_in_seconds_subtext), - new IconicsDrawable(activity) + new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_register_count_in_seconds_text) + .subText(R.string.settings_register_count_in_seconds_subtext) + .icon(new IconicsDrawable(activity) .icon(CommunityMaterial.Icon2.cmd_timer) .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) + .color(IconicsColor.colorInt(iconColor))) .setChecked(app.getConfig().getTimetable().getCountInSeconds()) - .setOnChangeAction((isChecked, tag) -> { + .setOnCheckedChanged((item, isChecked) -> { app.getConfig().getTimetable().setCountInSeconds(isChecked); return true; }) + .build() ); if (app.getProfile().getLoginStoreType() == LoginStore.LOGIN_TYPE_LIBRUS) { items.add( - new MaterialAboutSwitchItem( - getString(R.string.settings_register_show_teacher_absences_text), - null, - new IconicsDrawable(activity) + new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_register_show_teacher_absences_text) + .icon(new IconicsDrawable(activity) .icon(CommunityMaterial.Icon.cmd_account_arrow_right_outline) .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) + .color(IconicsColor.colorInt(iconColor))) .setChecked(app.getProfile().getStudentData("showTeacherAbsences", true)) - .setOnChangeAction((isChecked, tag) -> { + .setOnCheckedChanged((item, isChecked) -> { app.getProfile().putStudentData("showTeacherAbsences", isChecked); app.profileSave(); return true; }) + .build() ); } if (App.Companion.getDevMode()) { items.add( - new MaterialAboutSwitchItem( - getString(R.string.settings_register_hide_sticks_from_old), - null, - new IconicsDrawable(activity) - .icon(CommunityMaterial.Icon2.cmd_numeric_1_box_outline) - .size(IconicsSize.dp(iconSizeDp)) - .color(IconicsColor.colorInt(iconColor)) - ) + new MaterialAboutSwitchItem.Builder() + .text(R.string.settings_register_hide_sticks_from_old) + .icon(new IconicsDrawable(activity) + .icon(CommunityMaterial.Icon2.cmd_numeric_1_box_outline) + .size(IconicsSize.dp(iconSizeDp)) + .color(IconicsColor.colorInt(iconColor))) .setChecked(app.getConfig().forProfile().getGrades().getHideSticksFromOld()) - .setOnChangeAction((isChecked, tag) -> { + .setOnCheckedChanged((item, isChecked) -> { app.getConfig().forProfile().getGrades().setHideSticksFromOld(isChecked); return true; }) + .build() ); } @@ -1097,15 +1092,11 @@ public class SettingsNewFragment extends MaterialAboutFragment { items.add(new MaterialAboutTitleItem.Builder() .text(R.string.app_name) .desc(R.string.settings_about_title_subtext) - .textColor(primaryTextOnPrimaryBg) - .descColor(secondaryTextOnPrimaryBg) .icon(R.mipmap.ic_splash) .build()); pref_about_version = new MaterialAboutActionItem.Builder() .text(R.string.settings_about_version_text) - .textColor(primaryTextOnPrimaryBg) - .subTextColor(secondaryTextOnPrimaryBg) .subText(BuildConfig.VERSION_NAME + ", " + BuildConfig.BUILD_TYPE) .icon(new IconicsDrawable(activity) .icon(CommunityMaterial.Icon2.cmd_information_outline) @@ -1129,8 +1120,6 @@ public class SettingsNewFragment extends MaterialAboutFragment { items.add(new MaterialAboutActionItem.Builder() .text(R.string.settings_about_privacy_policy_text) - .textColor(primaryTextOnPrimaryBg) - .subTextColor(secondaryTextOnPrimaryBg) .icon(new IconicsDrawable(activity) .icon(CommunityMaterial.Icon2.cmd_shield_outline) .color(IconicsColor.colorInt(primaryTextOnPrimaryBg)) @@ -1140,8 +1129,6 @@ public class SettingsNewFragment extends MaterialAboutFragment { items.add(new MaterialAboutActionItem.Builder() .text(R.string.settings_about_discord_text) - .textColor(primaryTextOnPrimaryBg) - .subTextColor(secondaryTextOnPrimaryBg) .subText(R.string.settings_about_discord_subtext) .icon(new IconicsDrawable(activity) .icon(SzkolnyFont.Icon.szf_discord_outline) @@ -1152,8 +1139,6 @@ public class SettingsNewFragment extends MaterialAboutFragment { items.add(new MaterialAboutActionItem.Builder() .text(R.string.settings_about_language_text) - .textColor(primaryTextOnPrimaryBg) - .subTextColor(secondaryTextOnPrimaryBg) .subText(R.string.settings_about_language_subtext) .icon(new IconicsDrawable(activity) .icon(CommunityMaterial.Icon2.cmd_translate) @@ -1193,8 +1178,6 @@ public class SettingsNewFragment extends MaterialAboutFragment { items.add(new MaterialAboutActionItem.Builder() .text(R.string.settings_about_update_text) .subText(R.string.settings_about_update_subtext) - .textColor(primaryTextOnPrimaryBg) - .subTextColor(secondaryTextOnPrimaryBg) .icon(new IconicsDrawable(activity) .icon(CommunityMaterial.Icon2.cmd_update) .color(IconicsColor.colorInt(primaryTextOnPrimaryBg)) @@ -1218,8 +1201,6 @@ public class SettingsNewFragment extends MaterialAboutFragment { items.add(new MaterialAboutActionItem.Builder() .text(R.string.settings_about_changelog_text) - .textColor(primaryTextOnPrimaryBg) - .subTextColor(secondaryTextOnPrimaryBg) .icon(new IconicsDrawable(activity) .icon(CommunityMaterial.Icon2.cmd_radar) .color(IconicsColor.colorInt(primaryTextOnPrimaryBg)) @@ -1229,8 +1210,6 @@ public class SettingsNewFragment extends MaterialAboutFragment { items.add(new MaterialAboutActionItem.Builder() .text(R.string.settings_about_licenses_text) - .textColor(primaryTextOnPrimaryBg) - .subTextColor(secondaryTextOnPrimaryBg) .icon(new IconicsDrawable(activity) .icon(CommunityMaterial.Icon.cmd_code_braces) .color(IconicsColor.colorInt(primaryTextOnPrimaryBg)) @@ -1267,8 +1246,6 @@ public class SettingsNewFragment extends MaterialAboutFragment { items.add(new MaterialAboutActionItem.Builder() .text(R.string.settings_about_crash_text) .subText(R.string.settings_about_crash_subtext) - .textColor(primaryTextOnPrimaryBg) - .subTextColor(secondaryTextOnPrimaryBg) .icon(new IconicsDrawable(activity) .icon(CommunityMaterial.Icon.cmd_bug_outline) .color(IconicsColor.colorInt(primaryTextOnPrimaryBg)) @@ -1304,11 +1281,6 @@ public class SettingsNewFragment extends MaterialAboutFragment { return materialAboutList; } - @Override - protected int getTheme() { - return Themes.INSTANCE.getAppTheme(); - } - /* _____ _ ____ _ _ / ____| | | | _ \ | | | | | | _ _ ___| |_ ___ _ __ ___ | |_) | __ _ ___| | ____ _ _ __ ___ _ _ _ __ __| |___ diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 9983ecf0..512c6ade 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -111,12 +111,9 @@ ?colorAccent ?android:textColorPrimary - @style/Theme.Mal.Toolbar.Dark - @style/Theme.Mal.Toolbar.Light ?android:textColorPrimary ?android:textColorSecondary ?colorSurface - @color/dividerColor @drawable/timetable_lesson_bg_light #9f9f9f @@ -147,12 +144,9 @@ ?colorAccent ?android:textColorPrimary - @style/Theme.Mal.Toolbar.Dark - @style/Theme.Mal.Toolbar.Dark @color/primaryTextDark @color/secondaryTextDark ?colorSurface - @color/dividerColor @drawable/timetable_lesson_bg_dark #838383 diff --git a/material-about-library/build.gradle b/material-about-library/build.gradle deleted file mode 100644 index c79c427c..00000000 --- a/material-about-library/build.gradle +++ /dev/null @@ -1,38 +0,0 @@ -apply plugin: 'com.android.library' - -group = 'com.github.daniel-stoneuk' - -def versionMajor = 2 -def versionMinor = 3 -def versionPatch = 0 -def versionBuild = 0 // bump for dogfood builds, public betas, etc. - -android { - compileSdkVersion setup.compileSdk - - defaultConfig { - minSdkVersion 14 - targetSdkVersion setup.targetSdk - versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild - versionName "${versionMajor}.${versionMinor}" + (versionPatch == 0 ? "" : ".${versionPatch}") - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - debugMinify { - debuggable = true - minifyEnabled = true - proguardFiles 'proguard-android.txt' - } - } -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "androidx.appcompat:appcompat:${versions.appcompat}" - implementation "androidx.cardview:cardview:${versions.cardview}" - implementation "com.google.android.material:material:${versions.material}" -} diff --git a/material-about-library/src/main/AndroidManifest.xml b/material-about-library/src/main/AndroidManifest.xml deleted file mode 100644 index 71d1ecd9..00000000 --- a/material-about-library/src/main/AndroidManifest.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/ConvenienceBuilder.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/ConvenienceBuilder.java deleted file mode 100644 index f0e17e95..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/ConvenienceBuilder.java +++ /dev/null @@ -1,357 +0,0 @@ -package com.danielstone.materialaboutlibrary; - -import android.content.ActivityNotFoundException; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.graphics.drawable.Drawable; -import android.net.Uri; -import android.os.Build; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; -import android.webkit.WebView; -import android.widget.Toast; - -import com.danielstone.materialaboutlibrary.items.MaterialAboutActionItem; -import com.danielstone.materialaboutlibrary.items.MaterialAboutItemOnClickAction; -import com.danielstone.materialaboutlibrary.items.MaterialAboutTitleItem; -import com.danielstone.materialaboutlibrary.model.MaterialAboutCard; -import com.danielstone.materialaboutlibrary.util.OpenSourceLicense; - -@SuppressWarnings("JavaDoc") -public class ConvenienceBuilder { - - public static MaterialAboutTitleItem createAppTitleItem(String appName, Drawable applicationIcon) { - return new MaterialAboutTitleItem(appName, null, applicationIcon); - } - - public static MaterialAboutTitleItem createAppTitleItem(Context c) { - Context applicationContext = c.getApplicationContext(); - PackageManager packageManager = applicationContext.getPackageManager(); - ApplicationInfo applicationInfo = applicationContext.getApplicationInfo(); - CharSequence appName = packageManager.getApplicationLabel(applicationInfo); - Drawable applicationIcon = packageManager.getApplicationIcon(applicationInfo); - return createAppTitleItem(appName == null ? "" : appName.toString(), applicationIcon); - } - - /** - * Creates an item with version info read from the PackageManager for current application. - * - * @param c context - * @param icon - * @param text - * @param includeVersionCode - * @return Item to add to card. - */ - public static MaterialAboutActionItem createVersionActionItem(Context c, Drawable icon, CharSequence text, boolean includeVersionCode) { - String versionName = ""; - int versionCode = 0; - try { - PackageInfo pInfo = c.getPackageManager().getPackageInfo(c.getPackageName(), 0); - versionName = pInfo.versionName; - versionCode = pInfo.versionCode; - } catch (PackageManager.NameNotFoundException ignored) { - // This shouldn't happen. - } - return new MaterialAboutActionItem.Builder() - .text(text) - .subText(versionName + (includeVersionCode ? " (" + versionCode + ")" : "")) - .icon(icon) - .build(); - } - - public static MaterialAboutItemOnClickAction createWebViewDialogOnClickAction(final Context c, final CharSequence dialogTitle, final String htmlString, final boolean isStringUrl, final boolean supportZoom) { - return createWebViewDialogOnClickAction(c, dialogTitle, c.getString(R.string.mal_close), htmlString, isStringUrl, supportZoom); - } - - public static MaterialAboutItemOnClickAction createWebViewDialogOnClickAction(final Context c, final CharSequence dialogTitle, final CharSequence dialogNegativeButton, final String htmlString, final boolean isStringUrl, final boolean supportZoom) { - - return new MaterialAboutItemOnClickAction() { - @Override - public void onClick() { - AlertDialog.Builder alertBuilder = new AlertDialog.Builder(c); - alertBuilder.setTitle(dialogTitle); - - final WebView wv = new WebView(c); - wv.getSettings().setSupportZoom(supportZoom); - if (!supportZoom) { - wv.getSettings().setLoadWithOverviewMode(true); - wv.getSettings().setUseWideViewPort(true); - } - if (isStringUrl) { - wv.loadUrl(htmlString); - } else { - wv.loadData(htmlString, "text/html; charset=utf-8", "UTF-8"); - } - - alertBuilder.setView(wv); - alertBuilder.setNegativeButton(dialogNegativeButton, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - wv.destroy(); - dialog.dismiss(); - } - }); - - final AlertDialog dialog = alertBuilder.create(); - dialog.show(); - } - }; - } - - - public static MaterialAboutActionItem createWebViewDialogItem(Context c, Drawable icon, CharSequence text, @Nullable CharSequence subText, CharSequence dialogTitle, String htmlString, boolean isStringUrl, boolean supportZoom) { - return createWebViewDialogItem(c, icon, text, subText, dialogTitle, c.getString(R.string.mal_close), htmlString, isStringUrl, supportZoom); - } - - public static MaterialAboutActionItem createWebViewDialogItem(Context c, Drawable icon, CharSequence text, @Nullable CharSequence subText, CharSequence dialogTitle, CharSequence dialogNegativeButton, String htmlString, boolean isStringUrl, boolean supportZoom) { - return new MaterialAboutActionItem.Builder() - .text(text) - .subText(subText) - .icon(icon) - .setOnClickAction(createWebViewDialogOnClickAction(c, dialogTitle, dialogNegativeButton, htmlString, isStringUrl, supportZoom)) - .build(); - } - - - public static MaterialAboutItemOnClickAction createWebsiteOnClickAction(final Context c, final Uri websiteUrl) { - return new MaterialAboutItemOnClickAction() { - @Override - public void onClick() { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(websiteUrl); - try { - c.startActivity(i); - } catch (Exception e) { - // No activity to handle intent - Toast.makeText(c, R.string.mal_activity_exception, Toast.LENGTH_SHORT).show(); - } - } - }; - } - - /** - * Creates an ActionItem which will open a url when tapped - * - * @param c context - * @param text - * @param icon - * @param websiteUrl (subText) - * @return Item to add to card. - */ - public static MaterialAboutActionItem createWebsiteActionItem(Context c, Drawable icon, CharSequence text, boolean showAddress, final Uri websiteUrl) { - return new MaterialAboutActionItem.Builder() - .text(text) - .subText((showAddress ? websiteUrl.toString() : null)) - .icon(icon) - .setOnClickAction(createWebsiteOnClickAction(c, websiteUrl)) - .build(); - } - - /** - * Creates a MaterialAboutItemOnClickAction that will open - * the Google Play store listing for the app. - * - * @param c context - * @return onClickAction - */ - public static MaterialAboutItemOnClickAction createRateOnClickAction(final Context c) { - Uri uri = Uri.parse("market://details?id=" + c.getPackageName()); - final Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | - Intent.FLAG_ACTIVITY_NEW_DOCUMENT | - Intent.FLAG_ACTIVITY_MULTIPLE_TASK); - } else { - goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | - Intent.FLAG_ACTIVITY_MULTIPLE_TASK); - } - - return new MaterialAboutItemOnClickAction() { - @Override - public void onClick() { - try { - c.startActivity(goToMarket); - } catch (ActivityNotFoundException e) { - c.startActivity(new Intent(Intent.ACTION_VIEW, - Uri.parse("http://play.google.com/store/apps/details?id=" + c.getPackageName()))); - } - } - }; - } - - /** - * Creates an ActionItem which will open the play store when tapped - * - * @param c context - * @param text - * @param subText - * @param icon - * @return Item to add to card. - */ - public static MaterialAboutActionItem createRateActionItem(Context c, Drawable icon, CharSequence text, @Nullable CharSequence subText) { - - return new MaterialAboutActionItem.Builder() - .text(text) - .subText(subText) - .icon(icon) - .setOnClickAction(createRateOnClickAction(c)) - .build(); - } - - public static MaterialAboutItemOnClickAction createEmailOnClickAction(final Context c, String email, String emailSubject) { - return createEmailOnClickAction(c, email, emailSubject, c.getString(R.string.mal_send_email)); - } - - /** - * Creates a MaterialAboutItemOnClickAction that will open - * an email intent with specified address. - * - * @param c context - * @param email email address - * @return onClickAction - */ - public static MaterialAboutItemOnClickAction createEmailOnClickAction(final Context c, String email, String emailSubject, final CharSequence chooserTitle) { - - final Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + email)); - emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject); - - return new MaterialAboutItemOnClickAction() { - @Override - public void onClick() { - try { - c.startActivity(Intent.createChooser(emailIntent, chooserTitle)); - } catch (Exception e) { - // No activity to handle intent - Toast.makeText(c, R.string.mal_activity_exception, Toast.LENGTH_SHORT).show(); - } - } - }; - } - - /** - * Creates an ActionItem which will open the an email intent when tapped - * - * @param c context - * @param text - * @param icon - * @param email email address (also used as subText) - * @return Item to add to card. - */ - public static MaterialAboutActionItem createEmailItem(Context c, Drawable icon, CharSequence text, boolean showEmail, String email, String emailSubject, CharSequence chooserTitle) { - return new MaterialAboutActionItem.Builder() - .text(text) - .subText((showEmail ? email : null)) - .icon(icon) - .setOnClickAction(createEmailOnClickAction(c, email, emailSubject, chooserTitle)) - .build(); - } - - public static MaterialAboutActionItem createEmailItem(Context c, Drawable icon, CharSequence text, boolean showEmail, String email, String emailSubject) { - return createEmailItem(c, icon, text, showEmail, email, emailSubject, c.getString(R.string.mal_send_email)); - } - - /** - * Creates a MaterialAboutItemOnClickAction that will open - * the dialer with specified number. - * - * @param c context - * @param number phone number - * @return onClickAction - */ - public static MaterialAboutItemOnClickAction createPhoneOnClickAction(final Context c, String number) { - final Intent phoneIntent = new Intent(Intent.ACTION_DIAL); - phoneIntent.setData(Uri.parse("tel:" + number)); - - return new MaterialAboutItemOnClickAction() { - @Override - public void onClick() { - try { - c.startActivity(phoneIntent); - } catch (Exception e) { - // No activity to handle intent - Toast.makeText(c, R.string.mal_activity_exception, Toast.LENGTH_SHORT).show(); - } - } - }; - } - - /** - * Creates an ActionItem which will open the dialer when tapped - * - * @param c context - * @param text - * @param icon - * @param number phone number (also used as subText) - * @return Item to add to card. - */ - public static MaterialAboutActionItem createPhoneItem(Context c, Drawable icon, CharSequence text, boolean showNumber, String number) { - return new MaterialAboutActionItem.Builder() - .text(text) - .subText((showNumber ? number : null)) - .icon(icon) - .setOnClickAction(createPhoneOnClickAction(c, number)) - .build(); - } - - /** - * Creates a MaterialAboutItemOnClickAction that will open - * maps with a query. - * Query can be either lat,lng(label) or written address - * - * @param c context - * @param addressQuery address query - * @return onClickAction - */ - public static MaterialAboutItemOnClickAction createMapOnClickAction(final Context c, String addressQuery) { - final Intent mapIntent = new Intent(Intent.ACTION_VIEW); - mapIntent.setData(Uri.parse("geo:0,0").buildUpon().appendQueryParameter("q", addressQuery).build()); - return new MaterialAboutItemOnClickAction() { - @Override - public void onClick() { - try { - c.startActivity(mapIntent); - } catch (Exception e) { - // No activity to handle intent - Toast.makeText(c, R.string.mal_activity_exception, Toast.LENGTH_SHORT).show(); - } - } - }; - } - - /** - * Creates an ActionItem which will open maps when tapped - * Query can be either lat,lng(label) or written address - * - * @param c context - * @param text - * @param subText can be set to null - * @param icon - * @param addressQuery addressQuery - * @return Item to add to card. - */ - public static MaterialAboutActionItem createMapItem(Context c, Drawable icon, CharSequence text, CharSequence subText, String addressQuery) { - return new MaterialAboutActionItem.Builder() - .text(text) - .subText(subText) - .icon(icon) - .setOnClickAction(createMapOnClickAction(c, addressQuery)) - .build(); - } - - public static MaterialAboutCard createLicenseCard(Context c, Drawable icon, CharSequence libraryTitle, CharSequence year, CharSequence name, OpenSourceLicense license) { - - MaterialAboutActionItem licenseItem = new MaterialAboutActionItem.Builder() - .icon(icon) - .setIconGravity(MaterialAboutActionItem.GRAVITY_TOP) - .text(libraryTitle) - .subText(String.format(c.getString(license.getResourceId()), year, name)) - .build(); - - return new MaterialAboutCard.Builder().addItem(licenseItem).build(); - } - -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/MaterialAboutActivity.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/MaterialAboutActivity.java deleted file mode 100644 index 9a5ec841..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/MaterialAboutActivity.java +++ /dev/null @@ -1,186 +0,0 @@ -package com.danielstone.materialaboutlibrary; - - -import android.content.Context; -import android.os.AsyncTask; -import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import com.google.android.material.appbar.AppBarLayout; -import androidx.interpolator.view.animation.FastOutSlowInInterpolator; -import androidx.appcompat.app.ActionBar; -import androidx.appcompat.app.AppCompatActivity; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import androidx.recyclerview.widget.SimpleItemAnimator; -import androidx.appcompat.widget.Toolbar; -import android.util.TypedValue; -import android.view.MenuItem; - -import com.danielstone.materialaboutlibrary.adapters.MaterialAboutListAdapter; -import com.danielstone.materialaboutlibrary.model.MaterialAboutList; -import com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; - -import java.lang.ref.WeakReference; - -public abstract class MaterialAboutActivity extends AppCompatActivity { - - private MaterialAboutList list = new MaterialAboutList.Builder().build(); - private Toolbar toolbar; - private RecyclerView recyclerView; - private MaterialAboutListAdapter adapter; - - @NonNull - protected abstract MaterialAboutList getMaterialAboutList(@NonNull Context context); - - @Nullable - protected abstract CharSequence getActivityTitle(); - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - verifyAttributesExist(); - - setContentView(R.layout.mal_material_about_activity); - - CharSequence title = getActivityTitle(); - if (title == null) - setTitle(R.string.mal_title_about); - else - setTitle(title); - - - assignViews(); - initViews(); - - ListTask task = new ListTask(this); - task.execute(); - } - - private void verifyAttributesExist() { - TypedValue typedValue = new TypedValue(); - boolean malColorPrimaryExists = - getTheme().resolveAttribute(R.attr.mal_color_primary, typedValue, true); - boolean malColorSecondaryExists = - getTheme().resolveAttribute(R.attr.mal_color_secondary, typedValue, true); - if (!malColorPrimaryExists || !malColorSecondaryExists) { - throw new IllegalStateException(String.format("The current theme doesn't provide %s " + - "and/or %s. Please use a theme provided by the library or an extension.", - getResources().getResourceEntryName(R.attr.mal_color_primary), - getResources().getResourceEntryName(R.attr.mal_color_secondary))); - } - } - - private void assignViews() { - toolbar = (Toolbar) findViewById(R.id.mal_toolbar); - recyclerView = (RecyclerView) findViewById(R.id.mal_recyclerview); - recyclerView.setAlpha(0f); - recyclerView.setTranslationY(20); - } - - private void initViews() { - setSupportActionBar(toolbar); - ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - actionBar.setDisplayHomeAsUpEnabled(true); - } - adapter = new MaterialAboutListAdapter(getViewTypeManager()); - recyclerView.setLayoutManager(new LinearLayoutManager(this)); - recyclerView.setAdapter(adapter); - RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator(); - if (animator instanceof SimpleItemAnimator) { - ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false); - } - } - - @NonNull - protected ViewTypeManager getViewTypeManager() { - return new DefaultViewTypeManager(); - } - - @NonNull - protected MaterialAboutList getList() { - return list; - } - - protected boolean shouldAnimate() { - return true; - } - - protected void refreshMaterialAboutList() { - setMaterialAboutList(list); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - onBackPressed(); - return true; - } - return super.onOptionsItemSelected(item); - } - - private void onTaskFinished(@Nullable MaterialAboutList materialAboutList) { - if (materialAboutList != null) { - list = materialAboutList; - adapter.setData(list.getCards()); - - if (shouldAnimate()) { - recyclerView.animate() - .alpha(1f) - .translationY(0f) - .setDuration(600) - .setInterpolator(new FastOutSlowInInterpolator()).start(); - } else { - recyclerView.setAlpha(1f); - recyclerView.setTranslationY(0f); - } - } else { - finish();//?? why we remain here anyway? - } - } - - protected void setMaterialAboutList(MaterialAboutList materialAboutList) { - list = materialAboutList; - adapter.setData(list.getCards()); - } - - protected void setScrollToolbar(boolean scrollToolbar) { - if (toolbar != null) { - AppBarLayout.LayoutParams params = - (AppBarLayout.LayoutParams) toolbar.getLayoutParams(); - if (scrollToolbar) { - params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL - | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS); - } else { - params.setScrollFlags(0); - } - } - } - - private static class ListTask extends AsyncTask { - - private WeakReference context; - - ListTask(MaterialAboutActivity context) { - this.context = new WeakReference<>(context); - } - - @Override - protected MaterialAboutList doInBackground(String... params) { - return isCancelled() || context.get() == null ? null : context.get().getMaterialAboutList(context.get()); - } - - @Override - protected void onPostExecute(MaterialAboutList materialAboutList) { - super.onPostExecute(materialAboutList); - if (context.get() != null) { - if (!context.get().isFinishing()) { - context.get().onTaskFinished(materialAboutList); - } - } - context = null; - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/MaterialAboutFragment.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/MaterialAboutFragment.java deleted file mode 100644 index c3ad1f04..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/MaterialAboutFragment.java +++ /dev/null @@ -1,132 +0,0 @@ -package com.danielstone.materialaboutlibrary; - -import android.content.Context; -import android.os.AsyncTask; -import android.os.Bundle; - -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; -import androidx.interpolator.view.animation.FastOutSlowInInterpolator; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import androidx.recyclerview.widget.SimpleItemAnimator; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import com.danielstone.materialaboutlibrary.adapters.MaterialAboutListAdapter; -import com.danielstone.materialaboutlibrary.model.MaterialAboutList; -import com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; - -public abstract class MaterialAboutFragment extends Fragment { - - private MaterialAboutList list = new MaterialAboutList.Builder().build(); - private RecyclerView recyclerView; - private MaterialAboutListAdapter adapter; - - public static MaterialAboutFragment newInstance(MaterialAboutFragment fragment) { - return fragment; - } - - protected abstract MaterialAboutList getMaterialAboutList(Context activityContext); - - protected int getTheme() { - return R.style.Theme_Mal_Light; - } - - protected boolean shouldAnimate() { - return true; - } - - - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - int style = getTheme(); - - // create ContextThemeWrapper from the original Activity Context with the custom theme - final Context contextThemeWrapper = new android.view.ContextThemeWrapper(getActivity(), style); - LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper); - View rootView = localInflater.inflate(R.layout.mal_material_about_fragment, container, false); - - recyclerView = (RecyclerView) rootView.findViewById(R.id.mal_recyclerview); - adapter = new MaterialAboutListAdapter(getViewTypeManager()); - recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); - recyclerView.setAdapter(adapter); - - RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator(); - if (animator instanceof SimpleItemAnimator) { - ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false); - } - - recyclerView.setAlpha(0f); - recyclerView.setTranslationY(20); - - ListTask task = new ListTask(getActivity()); - task.execute(); - - return rootView; - } - - protected ViewTypeManager getViewTypeManager() { - return new DefaultViewTypeManager(); - } - - protected MaterialAboutList getList() { - return list; - } - - protected void setMaterialAboutList(MaterialAboutList materialAboutList) { - //recyclerView.stopScroll(); - //recyclerView.getRecycledViewPool().clear(); - list = materialAboutList; - adapter.setData(list.getCards()); - } - - @Override - public void onPause() { - super.onPause(); - } - - protected void refreshMaterialAboutList() { - setMaterialAboutList(list); - } - - private class ListTask extends AsyncTask { - - Context fragmentContext; - - public ListTask(Context activityContext) { - this.fragmentContext = activityContext; - } - - @Override - protected String doInBackground(String... params) { - list = getMaterialAboutList(fragmentContext); - return null; - } - - @Override - protected void onPostExecute(String s) { - if (list == null) - return;// TODO: 2019-05-09 dirty fix tbh - adapter.setData(list.getCards()); - - if (shouldAnimate()) { - recyclerView.animate() - .alpha(1f) - .translationY(0f) - .setDuration(600) - .setInterpolator(new FastOutSlowInInterpolator()) - .start(); - } else { - recyclerView.setAlpha(1f); - recyclerView.setTranslationY(0f); - } - - super.onPostExecute(s); - fragmentContext = null; - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/adapters/MaterialAboutItemAdapter.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/adapters/MaterialAboutItemAdapter.java deleted file mode 100644 index a3cd1e47..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/adapters/MaterialAboutItemAdapter.java +++ /dev/null @@ -1,167 +0,0 @@ -package com.danielstone.materialaboutlibrary.adapters; - -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.AsyncListDiffer; -import androidx.recyclerview.widget.DiffUtil; -import androidx.recyclerview.widget.RecyclerView; - -import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder; -import com.danielstone.materialaboutlibrary.items.MaterialAboutItem; -import com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class MaterialAboutItemAdapter extends RecyclerView.Adapter { - - private final AsyncListDiffer differ = new AsyncListDiffer(this, DIFF_CALLBACK); - - private ViewTypeManager viewTypeManager; - - private Context context; - - private List data = new ArrayList<>(); - private List oldData = new ArrayList<>(); - - MaterialAboutItemAdapter() { - setHasStableIds(true); - this.viewTypeManager = new DefaultViewTypeManager(); - } - - MaterialAboutItemAdapter(ViewTypeManager customViewTypeManager) { - //Log.d("MaterialItem", "Created adapter"); - setHasStableIds(true); - this.viewTypeManager = customViewTypeManager; - } - - @NonNull - @Override - public MaterialAboutItemViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) { - context = viewGroup.getContext(); - if (!(viewGroup instanceof RecyclerView)) { - throw new RuntimeException("Not bound to RecyclerView"); - } - - int layoutId = viewTypeManager.getLayout(viewType); - - View view = LayoutInflater.from(viewGroup.getContext()).inflate(layoutId, viewGroup, false); - view.setFocusable(true); - - return viewTypeManager.getViewHolder(viewType, view); - } - - @Override - public void onBindViewHolder(MaterialAboutItemViewHolder holder, int position) { - /*if (data.get(position) instanceof MaterialAboutSwitchItem) { - Log.d("MaterialAdapter", "Item "+((MaterialAboutSwitchItem) data.get(position)).getText()+" checked "+((MaterialAboutSwitchItem) data.get(position)).getChecked()); - }*/ - //Log.d("MaterialItem", "Binding "+data.get(position).getDetailString()); - viewTypeManager.setupItem(getItemViewType(position), holder, data.get(position), context); - } - - - @Override - public long getItemId(int position) { - return UUID.fromString(data.get(position).getId()).getMostSignificantBits() & Long.MAX_VALUE; - } - - @Override - public int getItemCount() { - return data.size(); - } - - @Override - public int getItemViewType(int position) { - return data.get(position).getType(); - } - - public void setData(ArrayList data) { - this.data = data; - - notifyDataSetChanged(); - // diff this with previous data - /*DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new MyDiffCallback(oldData, data)); - try { - diffResult.dispatchUpdatesTo(this); - } - catch (IllegalStateException e) { - e.printStackTrace(); - } - - // clone the new data to make further diffs - oldData = new ArrayList<>(); - for (MaterialAboutItem item : data) { - oldData.add(item.clone()); - }*/ - - /*List newData = new ArrayList<>(); - for (MaterialAboutItem item : data) { - newData.add(item.clone()); - } - differ.submitList(newData);*/ - } - - public List getData() { - return data; - } - - - public static final DiffUtil.ItemCallback DIFF_CALLBACK = new DiffUtil.ItemCallback() { - @Override - public boolean areItemsTheSame(MaterialAboutItem oldItem, MaterialAboutItem newItem) { - return oldItem.getId().equals(newItem.getId()); - } - - @Override - public boolean areContentsTheSame(MaterialAboutItem oldItem, MaterialAboutItem newItem) { - return oldItem.getDetailString().equals(newItem.getDetailString()); - } - }; - - public class MyDiffCallback extends DiffUtil.Callback{ - - List oldPersons; - List newPersons; - - public MyDiffCallback(List newPersons, List oldPersons) { - this.newPersons = newPersons; - this.oldPersons = oldPersons; - } - - @Override - public int getOldListSize() { - return oldPersons.size(); - } - - @Override - public int getNewListSize() { - return newPersons.size(); - } - - @Override - public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) { - return oldPersons.get(oldItemPosition).getId().equals(newPersons.get(newItemPosition).getId()); - } - - @Override - public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) { - return oldPersons.get(oldItemPosition).getDetailString().equals(newPersons.get(newItemPosition).getDetailString()); - } - - @Nullable - @Override - public Object getChangePayload(int oldItemPosition, int newItemPosition) { - //you can return particular field for changed item. - return super.getChangePayload(oldItemPosition, newItemPosition); - } - } - -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/adapters/MaterialAboutListAdapter.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/adapters/MaterialAboutListAdapter.java deleted file mode 100644 index e795ee31..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/adapters/MaterialAboutListAdapter.java +++ /dev/null @@ -1,237 +0,0 @@ -package com.danielstone.materialaboutlibrary.adapters; - -import android.content.Context; - -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.AsyncListDiffer; -import androidx.recyclerview.widget.DiffUtil; -import androidx.cardview.widget.CardView; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import com.danielstone.materialaboutlibrary.R; -import com.danielstone.materialaboutlibrary.model.MaterialAboutCard; -import com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; -import com.google.android.material.card.MaterialCardView; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class MaterialAboutListAdapter extends RecyclerView.Adapter { - - private final AsyncListDiffer differ = new AsyncListDiffer(this, DIFF_CALLBACK); - - private ViewTypeManager viewTypeManager; - - private Context context; - - private List data = new ArrayList<>(); - private List oldData = new ArrayList<>(); - - public MaterialAboutListAdapter() { - setHasStableIds(true); - this.viewTypeManager = new DefaultViewTypeManager(); - } - - public MaterialAboutListAdapter(ViewTypeManager customViewTypeManager) { - //Log.d("MaterialList", "Created list adapter"); - setHasStableIds(true); - this.viewTypeManager = customViewTypeManager; - } - - @Override - public MaterialAboutListViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { - context = viewGroup.getContext(); - if (viewGroup instanceof RecyclerView) { - View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.mal_material_about_list_card, viewGroup, false); - view.setFocusable(true); - return new MaterialAboutListViewHolder(view); - } else { - throw new RuntimeException("Not bound to RecyclerView"); - } - } - - @Override - public void onBindViewHolder(MaterialAboutListViewHolder holder, int position) { - MaterialAboutCard card = data.get(position); - - if (holder.cardView instanceof CardView) { - CardView cardView = (CardView) holder.cardView; - int cardColor = card.getCardColor(); - if (cardColor != 0) { - cardView.setCardBackgroundColor(cardColor); - } - } - - CharSequence title = card.getTitle(); - int titleRes = card.getTitleRes(); - - holder.title.setVisibility(View.VISIBLE); - if (title != null) { - holder.title.setText(title); - } else if (titleRes != 0) { - holder.title.setText(titleRes); - } else { - holder.title.setVisibility(View.GONE); - } - - int titleColor = card.getTitleColor(); - - if (holder.title.getVisibility() == View.VISIBLE) { - if (titleColor != 0) { - holder.title.setTextColor(titleColor); - } else { - holder.title.setTextColor(holder.title.getTextColors().getDefaultColor()); - } - } - - if (card.getCustomAdapter() != null) { - holder.useCustomAdapter(card.getCustomAdapter()); - } else { - holder.useMaterialAboutItemAdapter(); - ((MaterialAboutItemAdapter) holder.adapter).setData(card.getItems()); - } - } - - @Override - public long getItemId(int position) { - return UUID.fromString(data.get(position).getId()).getMostSignificantBits() & Long.MAX_VALUE; - } - - @Override - public int getItemCount() { - return data.size(); - } - - public void setData(ArrayList data) { - this.data = data; - - notifyDataSetChanged(); - - /*// diff this with previous data - DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new MyDiffCallback(oldData, data)); - try { - diffResult.dispatchUpdatesTo(this); - } - catch (IllegalStateException e) { - e.printStackTrace(); - } - - // clone the new data to make further diffs - oldData = new ArrayList<>(); - for (MaterialAboutCard card : data) { - oldData.add(card.clone()); - }*/ - //differ.submitList(newData); - } - - - List getData() { - return data; - } - - class MaterialAboutListViewHolder extends RecyclerView.ViewHolder { - - final View cardView; - final TextView title; - final RecyclerView recyclerView; - RecyclerView.Adapter adapter; - - MaterialAboutListViewHolder(View view) { - super(view); - cardView = view.findViewById(R.id.mal_list_card); - title = (TextView) view.findViewById(R.id.mal_list_card_title); - recyclerView = (RecyclerView) view.findViewById(R.id.mal_card_recyclerview); - adapter = new MaterialAboutItemAdapter(viewTypeManager); - recyclerView.setLayoutManager(new LinearLayoutManager(context)); - recyclerView.setAdapter(adapter); - recyclerView.setNestedScrollingEnabled(false); - } - - public void useMaterialAboutItemAdapter() { - if (!(adapter instanceof MaterialAboutItemAdapter)) { - adapter = new MaterialAboutItemAdapter(viewTypeManager); - recyclerView.setLayoutManager(new LinearLayoutManager(context)); - recyclerView.setAdapter(adapter); - } - } - - public void useCustomAdapter(RecyclerView.Adapter newAdapter) { - if (adapter instanceof MaterialAboutItemAdapter) { - recyclerView.setLayoutManager(new LinearLayoutManager(context)); - recyclerView.setAdapter(newAdapter); - } - } - } - - - public static final DiffUtil.ItemCallback DIFF_CALLBACK = new DiffUtil.ItemCallback() { - @Override - public boolean areItemsTheSame(MaterialAboutCard oldItem, MaterialAboutCard newItem) { - return oldItem.getId().equals(newItem.getId()); - } - - @Override - public boolean areContentsTheSame(MaterialAboutCard oldCard, MaterialAboutCard newCard) { - boolean result; - result = oldCard.toString().equals(newCard.toString()); - if (oldCard.getItems().size() != newCard.getItems().size()) return false; - for (int i = 0; i < oldCard.getItems().size(); i++) { - if (!oldCard.getItems().get(i).getDetailString().equals(newCard.getItems().get(i).getDetailString())) return false; - } - return result; - } - }; - - public class MyDiffCallback extends DiffUtil.Callback{ - - List oldPersons; - List newPersons; - - public MyDiffCallback(List newPersons, List oldPersons) { - this.newPersons = newPersons; - this.oldPersons = oldPersons; - } - - @Override - public int getOldListSize() { - return oldPersons.size(); - } - - @Override - public int getNewListSize() { - return newPersons.size(); - } - - @Override - public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) { - return oldPersons.get(oldItemPosition).getId().equals(newPersons.get(newItemPosition).getId()); - } - - @Override - public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) { - boolean result; - result = oldPersons.get(oldItemPosition).toString().equals(newPersons.get(newItemPosition).toString()); - if (oldPersons.get(oldItemPosition).getItems().size() != newPersons.get(newItemPosition).getItems().size()) return false; - for (int i = 0; i < oldPersons.get(oldItemPosition).getItems().size(); i++) { - if (!oldPersons.get(oldItemPosition).getItems().get(i).getDetailString().equals(newPersons.get(newItemPosition).getItems().get(i).getDetailString())) return false; - } - return result; - } - - @Nullable - @Override - public Object getChangePayload(int oldItemPosition, int newItemPosition) { - //you can return particular field for changed item. - return super.getChangePayload(oldItemPosition, newItemPosition); - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/holders/MaterialAboutItemViewHolder.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/holders/MaterialAboutItemViewHolder.java deleted file mode 100644 index 6188817b..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/holders/MaterialAboutItemViewHolder.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.danielstone.materialaboutlibrary.holders; - -import androidx.recyclerview.widget.RecyclerView; -import android.view.View; - -public abstract class MaterialAboutItemViewHolder extends RecyclerView.ViewHolder { - - public MaterialAboutItemViewHolder(View itemView) { - super(itemView); - } - -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutActionItem.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutActionItem.java deleted file mode 100644 index c69f106d..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutActionItem.java +++ /dev/null @@ -1,488 +0,0 @@ -package com.danielstone.materialaboutlibrary.items; - -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.os.Build; - -import androidx.annotation.ColorInt; -import androidx.annotation.DrawableRes; -import androidx.annotation.IntDef; -import androidx.annotation.StringRes; -import android.text.Html; -import android.util.TypedValue; -import android.view.Gravity; -import android.view.View; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.danielstone.materialaboutlibrary.R; -import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -import static android.view.View.GONE; - -public class MaterialAboutActionItem extends MaterialAboutItem { - - public static final int GRAVITY_TOP = 0; - public static final int GRAVITY_MIDDLE = 1; - public static final int GRAVITY_BOTTOM = 2; - private CharSequence text = null; - private int textRes = 0; - private CharSequence subText = null; - private int subTextRes = 0; - private int textColor = -1; - private int subTextColor = -1; - private Drawable icon = null; - private int iconRes = 0; - private boolean showIcon = true; - private int iconGravity = GRAVITY_MIDDLE; - private MaterialAboutItemOnClickAction onClickAction = null; - private MaterialAboutItemOnClickAction onLongClickAction = null; - - private MaterialAboutActionItem(Builder builder) { - super(); - this.text = builder.text; - this.textRes = builder.textRes; - - this.subText = builder.subText; - this.subTextRes = builder.subTextRes; - - this.textColor = builder.textColor; - this.subTextColor = builder.subTextColor; - - this.icon = builder.icon; - this.iconRes = builder.iconRes; - - this.showIcon = builder.showIcon; - - this.iconGravity = builder.iconGravity; - - this.onClickAction = builder.onClickAction; - this.onLongClickAction = builder.onLongClickAction; - } - - public MaterialAboutActionItem(CharSequence text, CharSequence subText, Drawable icon, MaterialAboutItemOnClickAction onClickAction) { - this.text = text; - this.subText = subText; - this.icon = icon; - this.onClickAction = onClickAction; - } - - public MaterialAboutActionItem(CharSequence text, CharSequence subText, Drawable icon) { - this.text = text; - this.subText = subText; - this.icon = icon; - } - - public MaterialAboutActionItem(int textRes, int subTextRes, int iconRes, MaterialAboutItemOnClickAction onClickAction) { - this.textRes = textRes; - this.subTextRes = subTextRes; - this.iconRes = iconRes; - this.onClickAction = onClickAction; - } - - public MaterialAboutActionItem(int textRes, int subTextRes, int iconRes) { - this.textRes = textRes; - this.subTextRes = subTextRes; - this.iconRes = iconRes; - } - - public static MaterialAboutItemViewHolder getViewHolder(View view) { - return new MaterialAboutActionItemViewHolder(view); - } - - public static void setupItem(MaterialAboutActionItemViewHolder holder, MaterialAboutActionItem item, Context context) { - CharSequence text = item.getText(); - int textRes = item.getTextRes(); - - holder.text.setVisibility(View.VISIBLE); - if (text != null) { - holder.text.setText(text); - } else if (textRes != 0) { - holder.text.setText(textRes); - } else { - holder.text.setVisibility(GONE); - } - - CharSequence subText = item.getSubText(); - int subTextRes = item.getSubTextRes(); - - holder.subText.setVisibility(View.VISIBLE); - if (subText != null) { - holder.subText.setText(subText); - } else if (subTextRes != 0) { - holder.subText.setText(subTextRes); - } else { - holder.subText.setVisibility(GONE); - } - - if (item.getTextColor() != -1) { - holder.text.setTextColor(item.getTextColor()); - } - if (item.getSubTextColor() != -1) { - holder.subText.setTextColor(item.getSubTextColor()); - } - - if (item.shouldShowIcon()) { - holder.icon.setVisibility(View.VISIBLE); - Drawable drawable = item.getIcon(); - int drawableRes = item.getIconRes(); - if (drawable != null) { - holder.icon.setImageDrawable(drawable); - } else if (drawableRes != 0) { - holder.icon.setImageResource(drawableRes); - } - } else { - holder.icon.setVisibility(GONE); - } - - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) holder.icon.getLayoutParams(); - switch (item.getIconGravity()) { - case MaterialAboutActionItem.GRAVITY_TOP: - params.gravity = Gravity.TOP; - break; - case MaterialAboutActionItem.GRAVITY_MIDDLE: - params.gravity = Gravity.CENTER_VERTICAL; - break; - case MaterialAboutActionItem.GRAVITY_BOTTOM: - params.gravity = Gravity.BOTTOM; - break; - } - holder.icon.setLayoutParams(params); - - int pL = 0, pT = 0, pR = 0, pB = 0; - if (Build.VERSION.SDK_INT < 21) { - pL = holder.view.getPaddingLeft(); - pT = holder.view.getPaddingTop(); - pR = holder.view.getPaddingRight(); - pB = holder.view.getPaddingBottom(); - } - - if (item.getOnClickAction() != null || item.getOnLongClickAction() != null) { - TypedValue outValue = new TypedValue(); - context.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true); - holder.view.setBackgroundResource(outValue.resourceId); - } else { - holder.view.setBackgroundResource(0); - } - holder.setOnClickAction(item.getOnClickAction()); - holder.setOnLongClickAction(item.getOnLongClickAction()); - - if (Build.VERSION.SDK_INT < 21) { - holder.view.setPadding(pL, pT, pR, pB); - } - } - - @Override - public int getType() { - return ViewTypeManager.ItemType.ACTION_ITEM; - } - - @Override - public String getDetailString() { - return "MaterialAboutActionItem{" + - "text=" + text + - ", textRes=" + textRes + - ", subText=" + subText + - ", subTextRes=" + subTextRes + - ", textColor=" + textColor + - ", descColor=" + subTextColor + - ", icon=" + icon + - ", iconRes=" + iconRes + - ", showIcon=" + showIcon + - ", iconGravity=" + iconGravity + - ", onClickAction=" + onClickAction + - ", onLongClickAction=" + onLongClickAction + - '}'; - } - - public MaterialAboutActionItem(MaterialAboutActionItem item) { - this.id = item.getId(); - this.text = item.getText(); - this.textRes = item.getTextRes(); - this.subText = item.getSubText(); - this.subTextRes = item.getSubTextRes(); - this.textColor = item.getTextColor(); - this.subTextColor = item.getSubTextColor(); - this.icon = item.getIcon(); - this.iconRes = item.getIconRes(); - this.showIcon = item.showIcon; - this.iconGravity = item.iconGravity; - this.onClickAction = item.onClickAction; - this.onLongClickAction = item.onLongClickAction; - } - - @Override - public MaterialAboutItem clone() { - return new MaterialAboutActionItem(this); - } - - public CharSequence getText() { - return text; - } - public MaterialAboutActionItem setText(CharSequence text) { - this.textRes = 0; - this.text = text; - return this; - } - - public int getTextRes() { - return textRes; - } - - public MaterialAboutActionItem setTextRes(int textRes) { - this.text = null; - this.textRes = textRes; - return this; - } - - public CharSequence getSubText() { - return subText; - } - - public MaterialAboutActionItem setSubText(CharSequence subText) { - this.subTextRes = 0; - this.subText = subText; - return this; - } - - public int getSubTextRes() { - return subTextRes; - } - - public MaterialAboutActionItem setSubTextRes(int subTextRes) { - this.subText = null; - this.subTextRes = subTextRes; - return this; - } - - public int getTextColor() { - return textColor; - } - - public MaterialAboutActionItem setTextColor(int textColor) { - this.textColor = textColor; - return this; - } - - public int getSubTextColor() { - return subTextColor; - } - - public MaterialAboutActionItem setSubTextColor(int subTextColor) { - this.subTextColor = subTextColor; - return this; - } - - public Drawable getIcon() { - return icon; - } - - public MaterialAboutActionItem setIcon(Drawable icon) { - this.iconRes = 0; - this.icon = icon; - return this; - } - - public int getIconRes() { - return iconRes; - } - - public MaterialAboutActionItem setIconRes(int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public boolean shouldShowIcon() { - return showIcon; - } - - public MaterialAboutActionItem setShouldShowIcon(boolean showIcon) { - this.showIcon = showIcon; - return this; - } - - @IconGravity - public int getIconGravity() { - return iconGravity; - } - - public MaterialAboutActionItem setIconGravity(int iconGravity) { - this.iconGravity = iconGravity; - return this; - } - - public MaterialAboutItemOnClickAction getOnClickAction() { - return onClickAction; - } - - public MaterialAboutActionItem setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - return this; - } - - public MaterialAboutItemOnClickAction getOnLongClickAction() { - return onLongClickAction; - } - - public MaterialAboutActionItem setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - return this; - } - - @Retention(RetentionPolicy.SOURCE) - @IntDef({GRAVITY_TOP, GRAVITY_MIDDLE, GRAVITY_BOTTOM}) - public @interface IconGravity { - } - - public static class MaterialAboutActionItemViewHolder extends MaterialAboutItemViewHolder implements View.OnClickListener, View.OnLongClickListener { - public final View view; - public final ImageView icon; - public final TextView text; - public final TextView subText; - private MaterialAboutItemOnClickAction onClickAction; - private MaterialAboutItemOnClickAction onLongClickAction; - - MaterialAboutActionItemViewHolder(View view) { - super(view); - this.view = view; - icon = (ImageView) view.findViewById(R.id.mal_item_image); - text = (TextView) view.findViewById(R.id.mal_item_text); - subText = (TextView) view.findViewById(R.id.mal_action_item_subtext); - } - - public void setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - view.setOnClickListener(onClickAction != null ? this : null); - } - - public void setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - view.setOnLongClickListener(onLongClickAction != null ? this : null); - } - - @Override - public void onClick(View v) { - if (onClickAction != null) { - onClickAction.onClick(); - } - } - - @Override - public boolean onLongClick(View v) { - if (onLongClickAction != null) { - onLongClickAction.onClick(); - return true; - } - return false; - } - } - - public static class Builder { - - MaterialAboutItemOnClickAction onClickAction = null; - MaterialAboutItemOnClickAction onLongClickAction = null; - private CharSequence text = null; - @StringRes - private int textRes = 0; - private CharSequence subText = null; - @StringRes - private int subTextRes = 0; - @ColorInt - private int textColor = -1; - @ColorInt - private int subTextColor = -1; - private Drawable icon = null; - @DrawableRes - private int iconRes = 0; - private boolean showIcon = true; - @IconGravity - private int iconGravity = GRAVITY_MIDDLE; - - public Builder text(CharSequence text) { - this.text = text; - this.textRes = 0; - return this; - } - - public Builder text(@StringRes int text) { - this.textRes = text; - this.text = null; - return this; - } - - public Builder subText(CharSequence subText) { - this.subText = subText; - this.subTextRes = 0; - return this; - } - - public Builder subText(@StringRes int subTextRes) { - this.subText = null; - this.subTextRes = subTextRes; - return this; - } - - public Builder textColor(@ColorInt int textColor) { - this.textColor = textColor; - return this; - } - - public Builder subTextColor(@ColorInt int subTextColor) { - this.subTextColor = subTextColor; - return this; - } - - public Builder subTextHtml(String subTextHtml) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - this.subText = Html.fromHtml(subTextHtml, Html.FROM_HTML_MODE_LEGACY); - } else { - //noinspection deprecation - this.subText = Html.fromHtml(subTextHtml); - } - this.subTextRes = 0; - return this; - } - - public Builder icon(Drawable icon) { - this.icon = icon; - this.iconRes = 0; - return this; - } - - public Builder icon(@DrawableRes int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public Builder showIcon(boolean showIcon) { - this.showIcon = showIcon; - return this; - } - - public Builder setIconGravity(@IconGravity int iconGravity) { - this.iconGravity = iconGravity; - return this; - } - - public Builder setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - return this; - } - - public Builder setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - return this; - } - - public MaterialAboutActionItem build() { - return new MaterialAboutActionItem(this); - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutActionSwitchItem.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutActionSwitchItem.java deleted file mode 100644 index eb6d9411..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutActionSwitchItem.java +++ /dev/null @@ -1,606 +0,0 @@ -package com.danielstone.materialaboutlibrary.items; - -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.os.Build; -import androidx.annotation.DrawableRes; -import androidx.annotation.IntDef; -import androidx.annotation.StringRes; -import androidx.appcompat.widget.SwitchCompat; - -import android.text.Html; -import android.util.TypedValue; -import android.view.Gravity; -import android.view.View; -import android.widget.CompoundButton; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.Switch; -import android.widget.TextView; - -import com.danielstone.materialaboutlibrary.R; -import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -import static android.view.View.GONE; - -public class MaterialAboutActionSwitchItem extends MaterialAboutItem { - - public static final int GRAVITY_TOP = 0; - public static final int GRAVITY_MIDDLE = 1; - public static final int GRAVITY_BOTTOM = 2; - private CharSequence text = null; - private int textRes = 0; - private CharSequence subText = null; - private int subTextRes = 0; - private CharSequence subTextChecked = null; - private int subTextCheckedRes = 0; - private Drawable icon = null; - private int iconRes = 0; - private boolean showIcon = true; - private int iconGravity = GRAVITY_MIDDLE; - private boolean checked = false; - private int tag = -1; - private MaterialAboutItemOnClickAction onClickAction = null; - private MaterialAboutItemOnClickAction onLongClickAction = null; - private MaterialAboutItemOnChangeAction onChangeAction = null; - - private MaterialAboutActionSwitchItem(Builder builder) { - super(); - this.text = builder.text; - this.textRes = builder.textRes; - - this.subText = builder.subText; - this.subTextRes = builder.subTextRes; - - this.subTextChecked = builder.subTextChecked; - this.subTextCheckedRes = builder.subTextCheckedRes; - - this.icon = builder.icon; - this.iconRes = builder.iconRes; - - this.showIcon = builder.showIcon; - - this.iconGravity = builder.iconGravity; - - this.checked = builder.checked; - - this.tag = builder.tag; - - this.onClickAction = builder.onClickAction; - this.onLongClickAction = builder.onLongClickAction; - this.onChangeAction = builder.onChangeAction; - } - - public MaterialAboutActionSwitchItem(CharSequence text, CharSequence subText, Drawable icon, MaterialAboutItemOnChangeAction onChangeAction) { - this.text = text; - this.subText = subText; - this.icon = icon; - this.onChangeAction = onChangeAction; - } - - public MaterialAboutActionSwitchItem(CharSequence text, CharSequence subText, Drawable icon) { - this.text = text; - this.subText = subText; - this.icon = icon; - } - - public MaterialAboutActionSwitchItem(int textRes, int subTextRes, int iconRes, MaterialAboutItemOnChangeAction onChangeAction) { - this.textRes = textRes; - this.subTextRes = subTextRes; - this.iconRes = iconRes; - this.onChangeAction = onChangeAction; - } - - public MaterialAboutActionSwitchItem(int textRes, int subTextRes, int iconRes) { - this.textRes = textRes; - this.subTextRes = subTextRes; - this.iconRes = iconRes; - } - - public static void setupItem(MaterialAboutActionSwitchItemViewHolder holder, MaterialAboutActionSwitchItem item, Context context) { - holder.switchItem = item; - - CharSequence text = item.getText(); - int textRes = item.getTextRes(); - - holder.text.setVisibility(View.VISIBLE); - if (text != null) { - holder.text.setText(text); - } else if (textRes != 0) { - holder.text.setText(textRes); - } else { - holder.text.setVisibility(GONE); - } - - CharSequence subText = item.getSubText(); - int subTextRes = item.getSubTextRes(); - - holder.subText.setVisibility(View.VISIBLE); - if (subText != null) { - holder.subText.setText(subText); - } else if (subTextRes != 0) { - holder.subText.setText(subTextRes); - } else { - holder.subText.setVisibility(GONE); - } - - if (item.shouldShowIcon()) { - holder.icon.setVisibility(View.VISIBLE); - Drawable drawable = item.getIcon(); - int drawableRes = item.getIconRes(); - if (drawable != null) { - holder.icon.setImageDrawable(drawable); - } else if (drawableRes != 0) { - holder.icon.setImageResource(drawableRes); - } - } else { - holder.icon.setVisibility(GONE); - } - - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) holder.icon.getLayoutParams(); - switch (item.getIconGravity()) { - case MaterialAboutActionSwitchItem.GRAVITY_TOP: - params.gravity = Gravity.TOP; - break; - case MaterialAboutActionSwitchItem.GRAVITY_MIDDLE: - params.gravity = Gravity.CENTER_VERTICAL; - break; - case MaterialAboutActionSwitchItem.GRAVITY_BOTTOM: - params.gravity = Gravity.BOTTOM; - break; - } - holder.icon.setLayoutParams(params); - - int pL = 0, pT = 0, pR = 0, pB = 0; - if (Build.VERSION.SDK_INT < 21) { - pL = holder.view.getPaddingLeft(); - pT = holder.view.getPaddingTop(); - pR = holder.view.getPaddingRight(); - pB = holder.view.getPaddingBottom(); - } - - holder.setChecked(item.getChecked()); - - if (item.getOnChangeAction() != null || item.getOnClickAction() != null || item.getOnLongClickAction() != null) { - TypedValue outValue = new TypedValue(); - context.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true); - holder.view.setBackgroundResource(outValue.resourceId); - } else { - holder.view.setBackgroundResource(0); - } - holder.setOnClickAction(item.getOnClickAction()); - holder.setOnLongClickAction(item.getOnLongClickAction()); - holder.setOnChangeAction(item.getOnChangeAction()); - - if (Build.VERSION.SDK_INT < 21) { - holder.view.setPadding(pL, pT, pR, pB); - } - } - - public static MaterialAboutItemViewHolder getViewHolder(View view) { - return new MaterialAboutActionSwitchItemViewHolder(view); - } - - public static class MaterialAboutActionSwitchItemViewHolder extends MaterialAboutItemViewHolder implements View.OnClickListener, View.OnLongClickListener, CompoundButton.OnCheckedChangeListener { - public final View view; - public final ImageView icon; - public final TextView text; - public final TextView subText; - public final SwitchCompat switchView; - private MaterialAboutItemOnClickAction onClickAction; - private MaterialAboutItemOnClickAction onLongClickAction; - private MaterialAboutItemOnChangeAction onChangeAction; - private MaterialAboutActionSwitchItem switchItem; - - MaterialAboutActionSwitchItemViewHolder(View view) { - super(view); - this.view = view.findViewById(R.id.mal_action_root); - icon = view.findViewById(R.id.mal_item_image); - text = view.findViewById(R.id.mal_item_text); - subText = view.findViewById(R.id.mal_action_item_subtext); - switchView = view.findViewById(R.id.mal_switch); - } - - public void setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - view.setOnClickListener(onClickAction != null ? this : null); - } - - public void setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - view.setOnLongClickListener(onLongClickAction != null ? this : null); - } - - public void setOnChangeAction(MaterialAboutItemOnChangeAction onChangeAction) { - this.onChangeAction = onChangeAction; - switchView.setOnCheckedChangeListener(this); - } - - public void setChecked(boolean checked) { - switchView.setChecked(checked); - switchItem.checked = checked; - updateSubText(checked); - } - - public void updateSubText(boolean checked) { - if (checked && switchItem.subTextChecked != null) { - subText.setText(switchItem.subTextChecked); - } - else if (checked && switchItem.subTextCheckedRes != 0) { - subText.setText(switchItem.subTextCheckedRes); - } - else if (switchItem.subText != null) { - subText.setText(switchItem.subText); - } - else if (switchItem.subTextRes != 0) { - subText.setText(switchItem.subTextRes); - } - } - - @Override - public void onClick(View v) { - if (onClickAction != null) { - onClickAction.onClick(); - } - } - - @Override - public boolean onLongClick(View v) { - if (onLongClickAction != null) { - onLongClickAction.onClick(); - return true; - } - return false; - } - - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - updateSubText(isChecked); - if (onChangeAction != null) { - if (!onChangeAction.onChange(isChecked, switchItem.getTag())) { - setChecked(!isChecked); - } - else { - switchItem.checked = isChecked; - } - } - else { - setChecked(!isChecked); - } - } - } - - @Override - public int getType() { - return ViewTypeManager.ItemType.ACTION_SWITCH_ITEM; - } - - @Override - public String getDetailString() { - return "MaterialAboutActionSwitchItem{" + - "text=" + text + - ", textRes=" + textRes + - ", subText=" + subText + - ", subTextRes=" + subTextRes + - ", subTextChecked=" + subTextChecked + - ", subTextCheckedRes=" + subTextCheckedRes + - ", icon=" + icon + - ", iconRes=" + iconRes + - ", showIcon=" + showIcon + - ", iconGravity=" + iconGravity + - ", checked=" + checked + - ", tag=" + tag + - ", onClickAction=" + onClickAction + - ", onLongClickAction=" + onLongClickAction + - ", onChangeAction=" + onChangeAction + - '}'; - } - - public MaterialAboutActionSwitchItem(MaterialAboutActionSwitchItem item) { - this.id = item.getId(); - this.text = item.getText(); - this.textRes = item.getTextRes(); - this.subText = item.getSubText(); - this.subTextRes = item.getSubTextRes(); - this.subTextChecked = item.getSubTextChecked(); - this.subTextCheckedRes = item.getSubTextCheckedRes(); - this.icon = item.getIcon(); - this.iconRes = item.getIconRes(); - this.showIcon = item.showIcon; - this.iconGravity = item.iconGravity; - this.checked = item.checked; - this.tag = item.tag; - this.onClickAction = item.onClickAction; - this.onLongClickAction = item.onLongClickAction; - this.onChangeAction = item.onChangeAction; - } - - @Override - public MaterialAboutItem clone() { - return new MaterialAboutActionSwitchItem(this); - } - - public int getTag() { - return tag; - } - public MaterialAboutActionSwitchItem setTag(int tag) { - this.tag = tag; - return this; - } - - public CharSequence getText() { - return text; - } - public MaterialAboutActionSwitchItem setText(CharSequence text) { - this.textRes = 0; - this.text = text; - return this; - } - - public int getTextRes() { - return textRes; - } - - public MaterialAboutActionSwitchItem setTextRes(int textRes) { - this.text = null; - this.textRes = textRes; - return this; - } - - public CharSequence getSubText() { - return subText; - } - - public MaterialAboutActionSwitchItem setSubText(CharSequence subText) { - this.subTextRes = 0; - this.subText = subText; - return this; - } - - public int getSubTextRes() { - return subTextRes; - } - - public MaterialAboutActionSwitchItem setSubTextRes(int subTextRes) { - this.subText = null; - this.subTextRes = subTextRes; - return this; - } - - public CharSequence getSubTextChecked() { - return subTextChecked; - } - - public MaterialAboutActionSwitchItem setSubTextChecked(CharSequence subTextChecked) { - this.subTextCheckedRes = 0; - this.subTextChecked = subTextChecked; - return this; - } - - public int getSubTextCheckedRes() { - return subTextCheckedRes; - } - - public MaterialAboutActionSwitchItem setSubTextCheckedRes(int subTextCheckedRes) { - this.subTextChecked = null; - this.subTextCheckedRes = subTextCheckedRes; - return this; - } - - public Drawable getIcon() { - return icon; - } - - public MaterialAboutActionSwitchItem setIcon(Drawable icon) { - this.iconRes = 0; - this.icon = icon; - return this; - } - - public int getIconRes() { - return iconRes; - } - - public MaterialAboutActionSwitchItem setIconRes(int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public boolean shouldShowIcon() { - return showIcon; - } - - public MaterialAboutActionSwitchItem setShouldShowIcon(boolean showIcon) { - this.showIcon = showIcon; - return this; - } - - @IconGravity - public int getIconGravity() { - return iconGravity; - } - - public MaterialAboutActionSwitchItem setIconGravity(int iconGravity) { - this.iconGravity = iconGravity; - return this; - } - - public boolean getChecked() { - return checked; - } - - public MaterialAboutActionSwitchItem setChecked(boolean checked) { - this.checked = checked; - return this; - } - - public MaterialAboutItemOnClickAction getOnClickAction() { - return onClickAction; - } - - public MaterialAboutActionSwitchItem setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - return this; - } - - public MaterialAboutItemOnClickAction getOnLongClickAction() { - return onLongClickAction; - } - - public MaterialAboutActionSwitchItem setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - return this; - } - - public MaterialAboutItemOnChangeAction getOnChangeAction() { - return onChangeAction; - } - - public MaterialAboutActionSwitchItem setOnChangeAction(MaterialAboutItemOnChangeAction onChangeAction) { - this.onChangeAction = onChangeAction; - return this; - } - - @Retention(RetentionPolicy.SOURCE) - @IntDef({GRAVITY_TOP, GRAVITY_MIDDLE, GRAVITY_BOTTOM}) - public @interface IconGravity { - } - - public static class Builder { - - MaterialAboutItemOnClickAction onClickAction = null; - MaterialAboutItemOnClickAction onLongClickAction = null; - MaterialAboutItemOnChangeAction onChangeAction = null; - private CharSequence text = null; - @StringRes - private int textRes = 0; - private CharSequence subText = null; - @StringRes - private int subTextRes = 0; - private CharSequence subTextChecked = null; - @StringRes - private int subTextCheckedRes = 0; - private Drawable icon = null; - @DrawableRes - private int iconRes = 0; - private boolean showIcon = true; - @IconGravity - private int iconGravity = GRAVITY_MIDDLE; - private boolean checked = false; - private int tag = -1; - - public Builder tag(int tag) { - this.tag = tag; - return this; - } - - public Builder text(CharSequence text) { - this.text = text; - this.textRes = 0; - return this; - } - - public Builder text(@StringRes int text) { - this.textRes = text; - this.text = null; - return this; - } - - public Builder subText(CharSequence subText) { - this.subText = subText; - this.subTextRes = 0; - return this; - } - - public Builder subText(@StringRes int subTextRes) { - this.subText = null; - this.subTextRes = subTextRes; - return this; - } - - public Builder subTextHtml(String subTextHtml) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - this.subText = Html.fromHtml(subTextHtml, Html.FROM_HTML_MODE_LEGACY); - } else { - //noinspection deprecation - this.subText = Html.fromHtml(subTextHtml); - } - this.subTextRes = 0; - return this; - } - - public Builder subTextChecked(CharSequence subTextChecked) { - this.subTextChecked = subTextChecked; - this.subTextCheckedRes = 0; - return this; - } - - public Builder subTextChecked(@StringRes int subTextCheckedRes) { - this.subTextChecked = null; - this.subTextCheckedRes = subTextCheckedRes; - return this; - } - - public Builder subTextCheckedHtml(String subTextCheckedHtml) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - this.subTextChecked = Html.fromHtml(subTextCheckedHtml, Html.FROM_HTML_MODE_LEGACY); - } else { - //noinspection deprecation - this.subTextChecked = Html.fromHtml(subTextCheckedHtml); - } - this.subTextCheckedRes = 0; - return this; - } - - public Builder icon(Drawable icon) { - this.icon = icon; - this.iconRes = 0; - return this; - } - - public Builder icon(@DrawableRes int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public Builder showIcon(boolean showIcon) { - this.showIcon = showIcon; - return this; - } - - public Builder setIconGravity(@IconGravity int iconGravity) { - this.iconGravity = iconGravity; - return this; - } - - public Builder setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - return this; - } - - public Builder setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - return this; - } - - public Builder setOnChangeAction(MaterialAboutItemOnChangeAction onChangeAction) { - this.onChangeAction = onChangeAction; - return this; - } - - public Builder checked(boolean isChecked) { - this.checked = isChecked; - return this; - } - - public MaterialAboutActionSwitchItem build() { - return new MaterialAboutActionSwitchItem(this); - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutCheckboxItem.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutCheckboxItem.java deleted file mode 100644 index 16a6cd45..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutCheckboxItem.java +++ /dev/null @@ -1,538 +0,0 @@ -package com.danielstone.materialaboutlibrary.items; - -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.os.Build; -import androidx.annotation.DrawableRes; -import androidx.annotation.IntDef; -import androidx.annotation.StringRes; -import android.text.Html; -import android.util.TypedValue; -import android.view.Gravity; -import android.view.View; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.danielstone.materialaboutlibrary.R; -import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -import static android.view.View.GONE; - -public class MaterialAboutCheckboxItem extends MaterialAboutItem { - - public static final int GRAVITY_TOP = 0; - public static final int GRAVITY_MIDDLE = 1; - public static final int GRAVITY_BOTTOM = 2; - private CharSequence text = null; - private int textRes = 0; - private CharSequence subText = null; - private int subTextRes = 0; - private CharSequence subTextChecked = null; - private int subTextCheckedRes = 0; - private Drawable icon = null; - private int iconRes = 0; - private boolean showIcon = true; - private int iconGravity = GRAVITY_MIDDLE; - private boolean checked = false; - private int tag = -1; - private MaterialAboutItemOnChangeAction onChangeAction = null; - - private MaterialAboutCheckboxItem(Builder builder) { - super(); - this.text = builder.text; - this.textRes = builder.textRes; - - this.subText = builder.subText; - this.subTextRes = builder.subTextRes; - - this.subTextChecked = builder.subTextChecked; - this.subTextCheckedRes = builder.subTextCheckedRes; - - this.icon = builder.icon; - this.iconRes = builder.iconRes; - - this.showIcon = builder.showIcon; - - this.iconGravity = builder.iconGravity; - - this.checked = builder.checked; - - this.tag = builder.tag; - - this.onChangeAction = builder.onChangeAction; - } - - public MaterialAboutCheckboxItem(CharSequence text, CharSequence subText, Drawable icon, MaterialAboutItemOnChangeAction onChangeAction) { - this.text = text; - this.subText = subText; - this.icon = icon; - this.onChangeAction = onChangeAction; - } - - public MaterialAboutCheckboxItem(CharSequence text, CharSequence subText, Drawable icon) { - this.text = text; - this.subText = subText; - this.icon = icon; - } - - public MaterialAboutCheckboxItem(int textRes, int subTextRes, int iconRes, MaterialAboutItemOnChangeAction onChangeAction) { - this.textRes = textRes; - this.subTextRes = subTextRes; - this.iconRes = iconRes; - this.onChangeAction = onChangeAction; - } - - public MaterialAboutCheckboxItem(int textRes, int subTextRes, int iconRes) { - this.textRes = textRes; - this.subTextRes = subTextRes; - this.iconRes = iconRes; - } - - public static MaterialAboutItemViewHolder getViewHolder(View view) { - return new MaterialAboutCheckboxItemViewHolder(view); - } - - public static void setupItem(MaterialAboutCheckboxItemViewHolder holder, MaterialAboutCheckboxItem item, Context context) { - holder.switchItem = item; - - CharSequence text = item.getText(); - int textRes = item.getTextRes(); - - holder.text.setVisibility(View.VISIBLE); - if (text != null) { - holder.text.setText(text); - } else if (textRes != 0) { - holder.text.setText(textRes); - } else { - holder.text.setVisibility(GONE); - } - - CharSequence subText = item.getSubText(); - int subTextRes = item.getSubTextRes(); - - holder.subText.setVisibility(View.VISIBLE); - if (subText != null) { - holder.subText.setText(subText); - } else if (subTextRes != 0) { - holder.subText.setText(subTextRes); - } else { - holder.subText.setVisibility(GONE); - } - - if (item.shouldShowIcon()) { - holder.icon.setVisibility(View.VISIBLE); - Drawable drawable = item.getIcon(); - int drawableRes = item.getIconRes(); - if (drawable != null) { - holder.icon.setImageDrawable(drawable); - } else if (drawableRes != 0) { - holder.icon.setImageResource(drawableRes); - } - } else { - holder.icon.setVisibility(GONE); - } - - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) holder.icon.getLayoutParams(); - switch (item.getIconGravity()) { - case MaterialAboutCheckboxItem.GRAVITY_TOP: - params.gravity = Gravity.TOP; - break; - case MaterialAboutCheckboxItem.GRAVITY_MIDDLE: - params.gravity = Gravity.CENTER_VERTICAL; - break; - case MaterialAboutCheckboxItem.GRAVITY_BOTTOM: - params.gravity = Gravity.BOTTOM; - break; - } - holder.icon.setLayoutParams(params); - - int pL = 0, pT = 0, pR = 0, pB = 0; - if (Build.VERSION.SDK_INT < 21) { - pL = holder.view.getPaddingLeft(); - pT = holder.view.getPaddingTop(); - pR = holder.view.getPaddingRight(); - pB = holder.view.getPaddingBottom(); - } - - - if (item.getOnChangeAction() != null) { - TypedValue outValue = new TypedValue(); - context.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true); - holder.view.setBackgroundResource(outValue.resourceId); - } else { - holder.view.setBackgroundResource(0); - } - holder.setOnChangeAction(item.getOnChangeAction()); - - if (Build.VERSION.SDK_INT < 21) { - holder.view.setPadding(pL, pT, pR, pB); - } - } - - @Override - public int getType() { - return ViewTypeManager.ItemType.CHECKBOX_ITEM; - } - - @Override - public String getDetailString() { - return "MaterialAboutCheckboxItem{" + - "text=" + text + - ", textRes=" + textRes + - ", subText=" + subText + - ", subTextRes=" + subTextRes + - ", subTextChecked=" + subTextChecked + - ", subTextCheckedRes=" + subTextCheckedRes + - ", icon=" + icon + - ", iconRes=" + iconRes + - ", showIcon=" + showIcon + - ", iconGravity=" + iconGravity + - ", checked=" + checked + - ", tag=" + tag + - ", onChangeAction=" + onChangeAction + - '}'; - } - - public MaterialAboutCheckboxItem(MaterialAboutCheckboxItem item) { - this.id = item.getId(); - this.text = item.getText(); - this.textRes = item.getTextRes(); - this.subText = item.getSubText(); - this.subTextRes = item.getSubTextRes(); - this.subTextChecked = item.getSubTextChecked(); - this.subTextCheckedRes = item.getSubTextCheckedRes(); - this.icon = item.getIcon(); - this.iconRes = item.getIconRes(); - this.showIcon = item.showIcon; - this.iconGravity = item.iconGravity; - this.checked = item.checked; - this.tag = item.tag; - this.onChangeAction = item.onChangeAction; - } - - @Override - public MaterialAboutItem clone() { - return new MaterialAboutCheckboxItem(this); - } - - public int getTag() { - return tag; - } - public MaterialAboutCheckboxItem setTag(int tag) { - this.tag = tag; - return this; - } - - public CharSequence getText() { - return text; - } - public MaterialAboutCheckboxItem setText(CharSequence text) { - this.textRes = 0; - this.text = text; - return this; - } - - public int getTextRes() { - return textRes; - } - - public MaterialAboutCheckboxItem setTextRes(int textRes) { - this.text = null; - this.textRes = textRes; - return this; - } - - public CharSequence getSubText() { - return subText; - } - - public MaterialAboutCheckboxItem setSubText(CharSequence subText) { - this.subTextRes = 0; - this.subText = subText; - return this; - } - - public int getSubTextRes() { - return subTextRes; - } - - public MaterialAboutCheckboxItem setSubTextRes(int subTextRes) { - this.subText = null; - this.subTextRes = subTextRes; - return this; - } - - public CharSequence getSubTextChecked() { - return subTextChecked; - } - - public MaterialAboutCheckboxItem setSubTextChecked(CharSequence subTextChecked) { - this.subTextCheckedRes = 0; - this.subTextChecked = subTextChecked; - return this; - } - - public int getSubTextCheckedRes() { - return subTextCheckedRes; - } - - public MaterialAboutCheckboxItem setSubTextCheckedRes(int subTextCheckedRes) { - this.subTextChecked = null; - this.subTextCheckedRes = subTextCheckedRes; - return this; - } - - public Drawable getIcon() { - return icon; - } - - public MaterialAboutCheckboxItem setIcon(Drawable icon) { - this.iconRes = 0; - this.icon = icon; - return this; - } - - public int getIconRes() { - return iconRes; - } - - public MaterialAboutCheckboxItem setIconRes(int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public boolean shouldShowIcon() { - return showIcon; - } - - public MaterialAboutCheckboxItem setShouldShowIcon(boolean showIcon) { - this.showIcon = showIcon; - return this; - } - - @IconGravity - public int getIconGravity() { - return iconGravity; - } - - public MaterialAboutCheckboxItem setIconGravity(int iconGravity) { - this.iconGravity = iconGravity; - return this; - } - - public boolean getChecked() { - return checked; - } - - public MaterialAboutCheckboxItem setChecked(boolean checked) { - this.checked = checked; - return this; - } - - public MaterialAboutItemOnChangeAction getOnChangeAction() { - return onChangeAction; - } - - public MaterialAboutCheckboxItem setOnChangeAction(MaterialAboutItemOnChangeAction onChangeAction) { - this.onChangeAction = onChangeAction; - return this; - } - - @Retention(RetentionPolicy.SOURCE) - @IntDef({GRAVITY_TOP, GRAVITY_MIDDLE, GRAVITY_BOTTOM}) - public @interface IconGravity { - } - - public static class MaterialAboutCheckboxItemViewHolder extends MaterialAboutItemViewHolder implements View.OnClickListener, CompoundButton.OnCheckedChangeListener { - public final View view; - public final ImageView icon; - public final TextView text; - public final TextView subText; - public final CheckBox checkBox; - private MaterialAboutItemOnChangeAction onChangeAction; - private MaterialAboutCheckboxItem switchItem; - - MaterialAboutCheckboxItemViewHolder(View view) { - super(view); - this.view = view; - icon = view.findViewById(R.id.mal_item_image); - text = view.findViewById(R.id.mal_item_text); - subText = view.findViewById(R.id.mal_action_item_subtext); - checkBox = view.findViewById(R.id.mal_checkbox); - } - - public void setOnChangeAction(MaterialAboutItemOnChangeAction onChangeAction) { - this.onChangeAction = onChangeAction; - view.setOnClickListener(onChangeAction != null ? this : null); - checkBox.setOnCheckedChangeListener(this); - } - - public void setChecked(boolean checked) { - checkBox.setOnCheckedChangeListener(null); - checkBox.setChecked(checked); - checkBox.setOnCheckedChangeListener(this); - updateSubText(checked); - } - - public void updateSubText(boolean checked) { - if (checked && switchItem.subTextChecked != null) { - subText.setText(switchItem.subTextChecked); - } - else if (checked && switchItem.subTextCheckedRes != 0) { - subText.setText(switchItem.subTextCheckedRes); - } - else if (switchItem.subText != null) { - subText.setText(switchItem.subText); - } - else if (switchItem.subTextRes != 0) { - subText.setText(switchItem.subTextRes); - } - } - - @Override - public void onClick(View v) { - checkBox.toggle(); - } - - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - updateSubText(isChecked); - if (onChangeAction != null) { - if (!onChangeAction.onChange(isChecked, switchItem.getTag())) - setChecked(!isChecked); - } - else { - setChecked(!isChecked); - } - } - } - - public static class Builder { - - MaterialAboutItemOnChangeAction onChangeAction = null; - private CharSequence text = null; - @StringRes - private int textRes = 0; - private CharSequence subText = null; - @StringRes - private int subTextRes = 0; - private CharSequence subTextChecked = null; - @StringRes - private int subTextCheckedRes = 0; - private Drawable icon = null; - @DrawableRes - private int iconRes = 0; - private boolean showIcon = true; - @IconGravity - private int iconGravity = GRAVITY_MIDDLE; - private boolean checked = false; - private int tag = -1; - - public Builder tag(int tag) { - this.tag = tag; - return this; - } - - public Builder text(CharSequence text) { - this.text = text; - this.textRes = 0; - return this; - } - - public Builder text(@StringRes int text) { - this.textRes = text; - this.text = null; - return this; - } - - public Builder subText(CharSequence subText) { - this.subText = subText; - this.subTextRes = 0; - return this; - } - - public Builder subText(@StringRes int subTextRes) { - this.subText = null; - this.subTextRes = subTextRes; - return this; - } - - public Builder subTextHtml(String subTextHtml) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - this.subText = Html.fromHtml(subTextHtml, Html.FROM_HTML_MODE_LEGACY); - } else { - //noinspection deprecation - this.subText = Html.fromHtml(subTextHtml); - } - this.subTextRes = 0; - return this; - } - - public Builder subTextChecked(CharSequence subTextChecked) { - this.subTextChecked = subTextChecked; - this.subTextCheckedRes = 0; - return this; - } - - public Builder subTextChecked(@StringRes int subTextCheckedRes) { - this.subTextChecked = null; - this.subTextCheckedRes = subTextCheckedRes; - return this; - } - - public Builder subTextCheckedHtml(String subTextCheckedHtml) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - this.subTextChecked = Html.fromHtml(subTextCheckedHtml, Html.FROM_HTML_MODE_LEGACY); - } else { - //noinspection deprecation - this.subTextChecked = Html.fromHtml(subTextCheckedHtml); - } - this.subTextCheckedRes = 0; - return this; - } - - public Builder icon(Drawable icon) { - this.icon = icon; - this.iconRes = 0; - return this; - } - - public Builder icon(@DrawableRes int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public Builder showIcon(boolean showIcon) { - this.showIcon = showIcon; - return this; - } - - public Builder setIconGravity(@IconGravity int iconGravity) { - this.iconGravity = iconGravity; - return this; - } - - public Builder setOnChangeAction(MaterialAboutItemOnChangeAction onChangeAction) { - this.onChangeAction = onChangeAction; - return this; - } - - public Builder checked(boolean isChecked) { - this.checked = isChecked; - return this; - } - - public MaterialAboutCheckboxItem build() { - return new MaterialAboutCheckboxItem(this); - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItem.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItem.java deleted file mode 100644 index 2d6a5f48..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItem.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.danielstone.materialaboutlibrary.items; - -import java.util.UUID; - -public abstract class MaterialAboutItem { - - public String id = "NO-UUID"; - - public MaterialAboutItem() { - this.id = UUID.randomUUID().toString(); - } - - public String getId() { - return id; - } - - public abstract int getType(); - - public abstract String getDetailString(); - - public abstract MaterialAboutItem clone(); - -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItemOnChangeAction.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItemOnChangeAction.java deleted file mode 100644 index 836883db..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItemOnChangeAction.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.danielstone.materialaboutlibrary.items; - -public interface MaterialAboutItemOnChangeAction { - boolean onChange(boolean isChecked, int tag); -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItemOnClickAction.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItemOnClickAction.java deleted file mode 100644 index ca1cd610..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItemOnClickAction.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.danielstone.materialaboutlibrary.items; - -public interface MaterialAboutItemOnClickAction { - void onClick(); -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutProfileItem.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutProfileItem.java deleted file mode 100644 index aeb4d4fe..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutProfileItem.java +++ /dev/null @@ -1,352 +0,0 @@ -package com.danielstone.materialaboutlibrary.items; - - -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.os.Build; -import androidx.annotation.DrawableRes; -import androidx.annotation.StringRes; - -import android.util.Log; -import android.util.TypedValue; -import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; - -import com.danielstone.materialaboutlibrary.R; -import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; - -import static android.view.View.GONE; - -public class MaterialAboutProfileItem extends MaterialAboutItem { - - private CharSequence text = null; - private int textRes = 0; - private CharSequence desc = null; - private int descRes = 0; - private Drawable icon = null; - private int iconRes = 0; - private MaterialAboutItemOnClickAction onClickAction = null; - private MaterialAboutItemOnClickAction onLongClickAction = null; - - private MaterialAboutProfileItem(MaterialAboutProfileItem.Builder builder) { - super(); - this.text = builder.text; - this.textRes = builder.textRes; - - this.desc = builder.desc; - this.descRes = builder.descRes; - - this.icon = builder.icon; - this.iconRes = builder.iconRes; - - this.onClickAction = builder.onClickAction; - this.onLongClickAction = builder.onLongClickAction; - } - - public MaterialAboutProfileItem(CharSequence text, CharSequence desc, Drawable icon) { - this.text = text; - this.desc = desc; - this.icon = icon; - } - - public MaterialAboutProfileItem(int textRes, int descRes, int iconRes) { - this.textRes = textRes; - this.descRes = descRes; - this.iconRes = iconRes; - } - - public static MaterialAboutItemViewHolder getViewHolder(View view) { - return new MaterialAboutProfileItem.MaterialAboutProfileItemViewHolder(view); - } - - public static void setupItem(MaterialAboutProfileItemViewHolder holder, MaterialAboutProfileItem item, Context context) { - - CharSequence text = item.getText(); - int textRes = item.getTextRes(); - - holder.text.setVisibility(View.VISIBLE); - if (text != null) { - holder.text.setText(text); - } else if (textRes != 0) { - holder.text.setText(textRes); - } else { - holder.text.setVisibility(GONE); - } - - CharSequence desc = item.getDesc(); - int descRes = item.getDescRes(); - - holder.desc.setVisibility(View.VISIBLE); - if (desc != null) { - holder.desc.setText(desc); - } else if (descRes != 0) { - holder.desc.setText(descRes); - } else { - holder.desc.setVisibility(GONE); - } - - Drawable drawable = item.getIcon(); - int drawableRes = item.getIconRes(); - if (drawable != null) { - holder.icon.setImageDrawable(drawable); - } else if (drawableRes != 0) { - holder.icon.setImageResource(drawableRes); - } - - int pL = 0, pT = 0, pR = 0, pB = 0; - if (Build.VERSION.SDK_INT < 21) { - pL = holder.view.getPaddingLeft(); - pT = holder.view.getPaddingTop(); - pR = holder.view.getPaddingRight(); - pB = holder.view.getPaddingBottom(); - } - - if (item.getOnClickAction() != null || item.getOnLongClickAction() != null) { - TypedValue outValue = new TypedValue(); - context.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true); - holder.view.setBackgroundResource(outValue.resourceId); - } else { - holder.view.setBackgroundResource(0); - } - holder.setOnClickAction(item.getOnClickAction()); - holder.setOnLongClickAction(item.getOnLongClickAction()); - - if (Build.VERSION.SDK_INT < 21) { - holder.view.setPadding(pL, pT, pR, pB); - } - } - - @Override - public int getType() { - return ViewTypeManager.ItemType.PROFILE_ITEM; - } - - @Override - public String getDetailString() { - return "MaterialAboutProfileItem{" + - "text=" + text + - ", textRes=" + textRes + - ", desc=" + desc + - ", descRes=" + descRes + - ", icon=" + icon + - ", iconRes=" + iconRes + - ", onClickAction=" + onClickAction + - ", onLongClickAction=" + onLongClickAction + - '}'; - } - - public MaterialAboutProfileItem(MaterialAboutProfileItem item) { - this.id = item.getId(); - this.text = item.getText(); - this.textRes = item.getTextRes(); - this.desc = item.getDesc(); - this.descRes = item.getDescRes(); - this.icon = item.getIcon(); - this.iconRes = item.getIconRes(); - this.onClickAction = item.getOnClickAction(); - this.onLongClickAction = item.getOnLongClickAction(); - } - - @Override - public MaterialAboutProfileItem clone() { - return new MaterialAboutProfileItem(this); - } - - public CharSequence getText() { - return text; - } - - public MaterialAboutProfileItem setText(CharSequence text) { - this.textRes = 0; - this.text = text; - return this; - } - - public int getTextRes() { - return textRes; - } - - public MaterialAboutProfileItem setTextRes(int textRes) { - this.text = null; - this.textRes = textRes; - return this; - } - - public CharSequence getDesc() { - return desc; - } - - public MaterialAboutProfileItem setDesc(CharSequence desc) { - this.descRes = 0; - this.desc = desc; - return this; - } - - public int getDescRes() { - return descRes; - } - - public MaterialAboutProfileItem setDescRes(int descRes) { - this.desc = null; - this.descRes = textRes; - return this; - } - - public Drawable getIcon() { - return icon; - } - - public MaterialAboutProfileItem setIcon(Drawable icon) { - this.iconRes = 0; - this.icon = icon; - return this; - } - - public int getIconRes() { - return iconRes; - } - - public MaterialAboutProfileItem setIconRes(int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public MaterialAboutItemOnClickAction getOnClickAction() { - return onClickAction; - } - - public MaterialAboutProfileItem setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - return this; - } - - public MaterialAboutItemOnClickAction getOnLongClickAction() { - return onLongClickAction; - } - - public MaterialAboutProfileItem setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - return this; - } - public static class MaterialAboutProfileItemViewHolder extends MaterialAboutItemViewHolder implements View.OnClickListener, View.OnLongClickListener { - public final View view; - public final ImageView icon; - public final TextView text; - public final TextView desc; - private MaterialAboutItemOnClickAction onClickAction; - private MaterialAboutItemOnClickAction onLongClickAction; - - MaterialAboutProfileItemViewHolder(View view) { - super(view); - this.view = view; - icon = (ImageView) view.findViewById(R.id.mal_item_image); - text = (TextView) view.findViewById(R.id.mal_item_text); - desc = (TextView) view.findViewById(R.id.mal_item_desc); - } - - public void setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - if (onClickAction != null) { - view.setOnClickListener(this); - } else { - view.setClickable(false); - } - } - - public void setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - if (onLongClickAction != null) { - view.setOnLongClickListener(this); - } else { - view.setLongClickable(false); - } - } - - @Override - public void onClick(View v) { - if (onClickAction != null) { - onClickAction.onClick(); - } - } - - @Override - public boolean onLongClick(View v) { - if (onLongClickAction != null) { - onLongClickAction.onClick(); - return true; - } - return false; - } - } - - public static class Builder { - - MaterialAboutItemOnClickAction onClickAction = null; - MaterialAboutItemOnClickAction onLongClickAction = null; - private CharSequence text = null; - @StringRes - private int textRes = 0; - private CharSequence desc = null; - @StringRes - private int descRes = 0; - private Drawable icon = null; - @DrawableRes - private int iconRes = 0; - - public MaterialAboutProfileItem.Builder text(CharSequence text) { - this.text = text; - this.textRes = 0; - return this; - } - - - public MaterialAboutProfileItem.Builder text(@StringRes int text) { - this.textRes = text; - this.text = null; - return this; - } - - public MaterialAboutProfileItem.Builder desc(CharSequence desc) { - this.desc = desc; - this.descRes = 0; - return this; - } - - - public MaterialAboutProfileItem.Builder desc(@StringRes int desc) { - this.descRes = desc; - this.desc = null; - return this; - } - - public MaterialAboutProfileItem.Builder icon(Drawable icon) { - this.icon = icon; - this.iconRes = 0; - return this; - } - - - public MaterialAboutProfileItem.Builder icon(@DrawableRes int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public MaterialAboutProfileItem.Builder setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - return this; - } - - public MaterialAboutProfileItem.Builder setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - return this; - } - - public MaterialAboutProfileItem build() { - return new MaterialAboutProfileItem(this); - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutSwitchItem.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutSwitchItem.java deleted file mode 100644 index 4ce55683..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutSwitchItem.java +++ /dev/null @@ -1,548 +0,0 @@ -package com.danielstone.materialaboutlibrary.items; - -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.os.Build; -import androidx.annotation.DrawableRes; -import androidx.annotation.IntDef; -import androidx.annotation.StringRes; -import androidx.appcompat.widget.SwitchCompat; - -import android.text.Html; -import android.util.Log; -import android.util.TypedValue; -import android.view.Gravity; -import android.view.View; -import android.widget.CompoundButton; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.Switch; -import android.widget.TextView; - -import com.danielstone.materialaboutlibrary.R; -import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -import static android.view.View.GONE; - -public class MaterialAboutSwitchItem extends MaterialAboutItem { - - public static final int GRAVITY_TOP = 0; - public static final int GRAVITY_MIDDLE = 1; - public static final int GRAVITY_BOTTOM = 2; - private CharSequence text = null; - private int textRes = 0; - private CharSequence subText = null; - private int subTextRes = 0; - private CharSequence subTextChecked = null; - private int subTextCheckedRes = 0; - private Drawable icon = null; - private int iconRes = 0; - private boolean showIcon = true; - private int iconGravity = GRAVITY_MIDDLE; - private boolean checked = false; - private int tag = -1; - private MaterialAboutItemOnChangeAction onChangeAction = null; - - private MaterialAboutSwitchItem(Builder builder) { - super(); - this.text = builder.text; - this.textRes = builder.textRes; - - this.subText = builder.subText; - this.subTextRes = builder.subTextRes; - - this.subTextChecked = builder.subTextChecked; - this.subTextCheckedRes = builder.subTextCheckedRes; - - this.icon = builder.icon; - this.iconRes = builder.iconRes; - - this.showIcon = builder.showIcon; - - this.iconGravity = builder.iconGravity; - - this.checked = builder.checked; - - this.tag = builder.tag; - - this.onChangeAction = builder.onChangeAction; - } - - public MaterialAboutSwitchItem(CharSequence text, CharSequence subText, Drawable icon, MaterialAboutItemOnChangeAction onChangeAction) { - this.text = text; - this.subText = subText; - this.icon = icon; - this.onChangeAction = onChangeAction; - } - - public MaterialAboutSwitchItem(CharSequence text, CharSequence subText, Drawable icon) { - this.text = text; - this.subText = subText; - this.icon = icon; - } - - public MaterialAboutSwitchItem(int textRes, int subTextRes, int iconRes, MaterialAboutItemOnChangeAction onChangeAction) { - this.textRes = textRes; - this.subTextRes = subTextRes; - this.iconRes = iconRes; - this.onChangeAction = onChangeAction; - } - - public MaterialAboutSwitchItem(int textRes, int subTextRes, int iconRes) { - this.textRes = textRes; - this.subTextRes = subTextRes; - this.iconRes = iconRes; - } - - public static void setupItem(MaterialAboutSwitchItemViewHolder holder, MaterialAboutSwitchItem item, Context context) { - holder.switchItem = item; - - CharSequence text = item.getText(); - int textRes = item.getTextRes(); - - holder.text.setVisibility(View.VISIBLE); - if (text != null) { - holder.text.setText(text); - } else if (textRes != 0) { - holder.text.setText(textRes); - } else { - holder.text.setVisibility(GONE); - } - - CharSequence subText = item.getSubText(); - int subTextRes = item.getSubTextRes(); - - holder.subText.setVisibility(View.VISIBLE); - if (subText != null) { - holder.subText.setText(subText); - } else if (subTextRes != 0) { - holder.subText.setText(subTextRes); - } else { - holder.subText.setVisibility(GONE); - } - - if (item.shouldShowIcon()) { - holder.icon.setVisibility(View.VISIBLE); - Drawable drawable = item.getIcon(); - int drawableRes = item.getIconRes(); - if (drawable != null) { - holder.icon.setImageDrawable(drawable); - } else if (drawableRes != 0) { - holder.icon.setImageResource(drawableRes); - } - } else { - holder.icon.setVisibility(GONE); - } - - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) holder.icon.getLayoutParams(); - switch (item.getIconGravity()) { - case MaterialAboutSwitchItem.GRAVITY_TOP: - params.gravity = Gravity.TOP; - break; - case MaterialAboutSwitchItem.GRAVITY_MIDDLE: - params.gravity = Gravity.CENTER_VERTICAL; - break; - case MaterialAboutSwitchItem.GRAVITY_BOTTOM: - params.gravity = Gravity.BOTTOM; - break; - } - holder.icon.setLayoutParams(params); - - int pL = 0, pT = 0, pR = 0, pB = 0; - if (Build.VERSION.SDK_INT < 21) { - pL = holder.view.getPaddingLeft(); - pT = holder.view.getPaddingTop(); - pR = holder.view.getPaddingRight(); - pB = holder.view.getPaddingBottom(); - } - - holder.setChecked(item.getChecked()); - - if (item.getOnChangeAction() != null) { - TypedValue outValue = new TypedValue(); - context.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true); - holder.view.setBackgroundResource(outValue.resourceId); - } else { - holder.view.setBackgroundResource(0); - } - holder.setOnChangeAction(item.getOnChangeAction()); - - if (Build.VERSION.SDK_INT < 21) { - holder.view.setPadding(pL, pT, pR, pB); - } - } - - public static MaterialAboutItemViewHolder getViewHolder(View view) { - return new MaterialAboutSwitchItemViewHolder(view); - } - - public static class MaterialAboutSwitchItemViewHolder extends MaterialAboutItemViewHolder implements View.OnClickListener, CompoundButton.OnCheckedChangeListener { - public final View view; - public final ImageView icon; - public final TextView text; - public final TextView subText; - public final SwitchCompat switchView; - private MaterialAboutItemOnChangeAction onChangeAction; - private MaterialAboutSwitchItem switchItem; - - MaterialAboutSwitchItemViewHolder(View view) { - super(view); - this.view = view; - icon = view.findViewById(R.id.mal_item_image); - text = view.findViewById(R.id.mal_item_text); - subText = view.findViewById(R.id.mal_action_item_subtext); - switchView = view.findViewById(R.id.mal_switch); - } - - public void setOnChangeAction(MaterialAboutItemOnChangeAction onChangeAction) { - this.onChangeAction = onChangeAction; - view.setOnClickListener(onChangeAction != null ? this : null); - switchView.setOnCheckedChangeListener(this); - } - - public void setChecked(boolean checked) { - switchView.setOnCheckedChangeListener(null); - switchView.setChecked(checked); - switchView.setOnCheckedChangeListener(this); - switchItem.setChecked(checked); - updateSubText(checked); - } - - public void updateSubText(boolean checked) { - if (checked && switchItem.subTextChecked != null) { - subText.setText(switchItem.subTextChecked); - } - else if (checked && switchItem.subTextCheckedRes != 0) { - subText.setText(switchItem.subTextCheckedRes); - } - else if (switchItem.subText != null) { - subText.setText(switchItem.subText); - } - else if (switchItem.subTextRes != 0) { - subText.setText(switchItem.subTextRes); - } - } - - @Override - public void onClick(View v) { - switchView.toggle(); - } - - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - updateSubText(isChecked); - if (onChangeAction != null) { - if (!onChangeAction.onChange(isChecked, switchItem.getTag())) { - setChecked(!isChecked); - } - else { - switchItem.setChecked(isChecked); - } - } - else { - setChecked(!isChecked); - } - } - } - - @Override - public int getType() { - return ViewTypeManager.ItemType.SWITCH_ITEM; - } - - @Override - public String getDetailString() { - return "MaterialAboutSwitchItem{" + - "text=" + text + - ", textRes=" + textRes + - ", subText=" + subText + - ", subTextRes=" + subTextRes + - ", subTextChecked=" + subTextChecked + - ", subTextCheckedRes=" + subTextCheckedRes + - ", icon=" + icon + - ", iconRes=" + iconRes + - ", showIcon=" + showIcon + - ", iconGravity=" + iconGravity + - ", checked=" + checked + - ", tag=" + tag + - ", onChangeAction=" + onChangeAction + - '}'; - } - - public MaterialAboutSwitchItem(MaterialAboutSwitchItem item) { - this.id = item.getId(); - this.text = item.getText(); - this.textRes = item.getTextRes(); - this.subText = item.getSubText(); - this.subTextRes = item.getSubTextRes(); - this.subTextChecked = item.getSubTextChecked(); - this.subTextCheckedRes = item.getSubTextCheckedRes(); - this.icon = item.getIcon(); - this.iconRes = item.getIconRes(); - this.showIcon = item.showIcon; - this.iconGravity = item.iconGravity; - this.checked = item.checked; - this.tag = item.tag; - this.onChangeAction = item.onChangeAction; - } - - @Override - public MaterialAboutItem clone() { - return new MaterialAboutSwitchItem(this); - } - - public int getTag() { - return tag; - } - public MaterialAboutSwitchItem setTag(int tag) { - this.tag = tag; - return this; - } - - public CharSequence getText() { - return text; - } - public MaterialAboutSwitchItem setText(CharSequence text) { - this.textRes = 0; - this.text = text; - return this; - } - - public int getTextRes() { - return textRes; - } - - public MaterialAboutSwitchItem setTextRes(int textRes) { - this.text = null; - this.textRes = textRes; - return this; - } - - public CharSequence getSubText() { - return subText; - } - - public MaterialAboutSwitchItem setSubText(CharSequence subText) { - this.subTextRes = 0; - this.subText = subText; - return this; - } - - public int getSubTextRes() { - return subTextRes; - } - - public MaterialAboutSwitchItem setSubTextRes(int subTextRes) { - this.subText = null; - this.subTextRes = subTextRes; - return this; - } - - public CharSequence getSubTextChecked() { - return subTextChecked; - } - - public MaterialAboutSwitchItem setSubTextChecked(CharSequence subTextChecked) { - this.subTextCheckedRes = 0; - this.subTextChecked = subTextChecked; - return this; - } - - public int getSubTextCheckedRes() { - return subTextCheckedRes; - } - - public MaterialAboutSwitchItem setSubTextCheckedRes(int subTextCheckedRes) { - this.subTextChecked = null; - this.subTextCheckedRes = subTextCheckedRes; - return this; - } - - public Drawable getIcon() { - return icon; - } - - public MaterialAboutSwitchItem setIcon(Drawable icon) { - this.iconRes = 0; - this.icon = icon; - return this; - } - - public int getIconRes() { - return iconRes; - } - - public MaterialAboutSwitchItem setIconRes(int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public boolean shouldShowIcon() { - return showIcon; - } - - public MaterialAboutSwitchItem setShouldShowIcon(boolean showIcon) { - this.showIcon = showIcon; - return this; - } - - @IconGravity - public int getIconGravity() { - return iconGravity; - } - - public MaterialAboutSwitchItem setIconGravity(int iconGravity) { - this.iconGravity = iconGravity; - return this; - } - - public boolean getChecked() { - return checked; - } - - public MaterialAboutSwitchItem setChecked(boolean checked) { - //Log.d("MaterialItem", "Setting item "+getText()+" to checked "+checked); - this.checked = checked; - return this; - } - - public MaterialAboutItemOnChangeAction getOnChangeAction() { - return onChangeAction; - } - - public MaterialAboutSwitchItem setOnChangeAction(MaterialAboutItemOnChangeAction onChangeAction) { - this.onChangeAction = onChangeAction; - return this; - } - - @Retention(RetentionPolicy.SOURCE) - @IntDef({GRAVITY_TOP, GRAVITY_MIDDLE, GRAVITY_BOTTOM}) - public @interface IconGravity { - } - - public static class Builder { - - MaterialAboutItemOnChangeAction onChangeAction = null; - private CharSequence text = null; - @StringRes - private int textRes = 0; - private CharSequence subText = null; - @StringRes - private int subTextRes = 0; - private CharSequence subTextChecked = null; - @StringRes - private int subTextCheckedRes = 0; - private Drawable icon = null; - @DrawableRes - private int iconRes = 0; - private boolean showIcon = true; - @IconGravity - private int iconGravity = GRAVITY_MIDDLE; - private boolean checked = false; - private int tag = -1; - - public Builder tag(int tag) { - this.tag = tag; - return this; - } - - public Builder text(CharSequence text) { - this.text = text; - this.textRes = 0; - return this; - } - - public Builder text(@StringRes int text) { - this.textRes = text; - this.text = null; - return this; - } - - public Builder subText(CharSequence subText) { - this.subText = subText; - this.subTextRes = 0; - return this; - } - - public Builder subText(@StringRes int subTextRes) { - this.subText = null; - this.subTextRes = subTextRes; - return this; - } - - public Builder subTextHtml(String subTextHtml) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - this.subText = Html.fromHtml(subTextHtml, Html.FROM_HTML_MODE_LEGACY); - } else { - //noinspection deprecation - this.subText = Html.fromHtml(subTextHtml); - } - this.subTextRes = 0; - return this; - } - - public Builder subTextChecked(CharSequence subTextChecked) { - this.subTextChecked = subTextChecked; - this.subTextCheckedRes = 0; - return this; - } - - public Builder subTextChecked(@StringRes int subTextCheckedRes) { - this.subTextChecked = null; - this.subTextCheckedRes = subTextCheckedRes; - return this; - } - - public Builder subTextCheckedHtml(String subTextCheckedHtml) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - this.subTextChecked = Html.fromHtml(subTextCheckedHtml, Html.FROM_HTML_MODE_LEGACY); - } else { - //noinspection deprecation - this.subTextChecked = Html.fromHtml(subTextCheckedHtml); - } - this.subTextCheckedRes = 0; - return this; - } - - public Builder icon(Drawable icon) { - this.icon = icon; - this.iconRes = 0; - return this; - } - - public Builder icon(@DrawableRes int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public Builder showIcon(boolean showIcon) { - this.showIcon = showIcon; - return this; - } - - public Builder setIconGravity(@IconGravity int iconGravity) { - this.iconGravity = iconGravity; - return this; - } - - public Builder setOnChangeAction(MaterialAboutItemOnChangeAction onChangeAction) { - this.onChangeAction = onChangeAction; - return this; - } - - public Builder checked(boolean isChecked) { - this.checked = isChecked; - return this; - } - - public MaterialAboutSwitchItem build() { - return new MaterialAboutSwitchItem(this); - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutTitleItem.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutTitleItem.java deleted file mode 100644 index a1b1bc72..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutTitleItem.java +++ /dev/null @@ -1,400 +0,0 @@ -package com.danielstone.materialaboutlibrary.items; - - -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.os.Build; - -import androidx.annotation.ColorInt; -import androidx.annotation.DrawableRes; -import androidx.annotation.StringRes; -import android.util.TypedValue; -import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; - -import com.danielstone.materialaboutlibrary.R; -import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder; -import com.danielstone.materialaboutlibrary.util.ViewTypeManager; - -import static android.view.View.GONE; - -public class MaterialAboutTitleItem extends MaterialAboutItem { - - private CharSequence text = null; - private int textRes = 0; - private CharSequence desc = null; - private int descRes = 0; - private int textColor = -1; - private int descColor = -1; - private Drawable icon = null; - private int iconRes = 0; - private MaterialAboutItemOnClickAction onClickAction = null; - private MaterialAboutItemOnClickAction onLongClickAction = null; - - private MaterialAboutTitleItem(MaterialAboutTitleItem.Builder builder) { - super(); - this.text = builder.text; - this.textRes = builder.textRes; - - this.desc = builder.desc; - this.descRes = builder.descRes; - - this.textColor = builder.textColor; - this.descColor = builder.descColor; - - this.icon = builder.icon; - this.iconRes = builder.iconRes; - - this.onClickAction = builder.onClickAction; - this.onLongClickAction = builder.onLongClickAction; - } - - public MaterialAboutTitleItem(CharSequence text, CharSequence desc, Drawable icon) { - this.text = text; - this.desc = desc; - this.icon = icon; - } - - public MaterialAboutTitleItem(int textRes, int descRes, int iconRes) { - this.textRes = textRes; - this.descRes = descRes; - this.iconRes = iconRes; - } - - public static MaterialAboutItemViewHolder getViewHolder(View view) { - return new MaterialAboutTitleItem.MaterialAboutTitleItemViewHolder(view); - } - - public static void setupItem(MaterialAboutTitleItemViewHolder holder, MaterialAboutTitleItem item, Context context) { - - CharSequence text = item.getText(); - int textRes = item.getTextRes(); - - holder.text.setVisibility(View.VISIBLE); - if (text != null) { - holder.text.setText(text); - } else if (textRes != 0) { - holder.text.setText(textRes); - } else { - holder.text.setVisibility(GONE); - } - - CharSequence desc = item.getDesc(); - int descRes = item.getDescRes(); - - holder.desc.setVisibility(View.VISIBLE); - if (desc != null) { - holder.desc.setText(desc); - } else if (descRes != 0) { - holder.desc.setText(descRes); - } else { - holder.desc.setVisibility(GONE); - } - - if (item.getTextColor() != -1) { - holder.text.setTextColor(item.getTextColor()); - } - if (item.getDescColor() != -1) { - holder.desc.setTextColor(item.getDescColor()); - } - - Drawable drawable = item.getIcon(); - int drawableRes = item.getIconRes(); - if (drawable != null) { - holder.icon.setImageDrawable(drawable); - } else if (drawableRes != 0) { - holder.icon.setImageResource(drawableRes); - } - - int pL = 0, pT = 0, pR = 0, pB = 0; - if (Build.VERSION.SDK_INT < 21) { - pL = holder.view.getPaddingLeft(); - pT = holder.view.getPaddingTop(); - pR = holder.view.getPaddingRight(); - pB = holder.view.getPaddingBottom(); - } - - if (item.getOnClickAction() != null || item.getOnLongClickAction() != null) { - TypedValue outValue = new TypedValue(); - context.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true); - holder.view.setBackgroundResource(outValue.resourceId); - } else { - holder.view.setBackgroundResource(0); - } - holder.setOnClickAction(item.getOnClickAction()); - holder.setOnLongClickAction(item.getOnLongClickAction()); - - if (Build.VERSION.SDK_INT < 21) { - holder.view.setPadding(pL, pT, pR, pB); - } - } - - @Override - public int getType() { - return ViewTypeManager.ItemType.TITLE_ITEM; - } - - @Override - public String getDetailString() { - return "MaterialAboutTitleItem{" + - "text=" + text + - ", textRes=" + textRes + - ", desc=" + desc + - ", descRes=" + descRes + - ", textColor=" + textColor + - ", descColor=" + descColor + - ", icon=" + icon + - ", iconRes=" + iconRes + - ", onClickAction=" + onClickAction + - ", onLongClickAction=" + onLongClickAction + - '}'; - } - - public MaterialAboutTitleItem(MaterialAboutTitleItem item) { - this.id = item.getId(); - this.text = item.getText(); - this.textRes = item.getTextRes(); - this.desc = item.getDesc(); - this.descRes = item.getDescRes(); - this.textColor = item.getTextColor(); - this.descColor = item.getDescColor(); - this.icon = item.getIcon(); - this.iconRes = item.getIconRes(); - this.onClickAction = item.getOnClickAction(); - this.onLongClickAction = item.getOnLongClickAction(); - } - - @Override - public MaterialAboutTitleItem clone() { - return new MaterialAboutTitleItem(this); - } - - public CharSequence getText() { - return text; - } - - public MaterialAboutTitleItem setText(CharSequence text) { - this.textRes = 0; - this.text = text; - return this; - } - - public int getTextRes() { - return textRes; - } - - public MaterialAboutTitleItem setTextRes(int textRes) { - this.text = null; - this.textRes = textRes; - return this; - } - - public CharSequence getDesc() { - return desc; - } - - public MaterialAboutTitleItem setDesc(CharSequence desc) { - this.descRes = 0; - this.desc = desc; - return this; - } - - public int getDescRes() { - return descRes; - } - - public MaterialAboutTitleItem setDescRes(int descRes) { - this.desc = null; - this.descRes = textRes; - return this; - } - - public int getTextColor() { - return textColor; - } - - public MaterialAboutTitleItem setTextColor(int textColor) { - this.textColor = textColor; - return this; - } - - public int getDescColor() { - return descColor; - } - - public MaterialAboutTitleItem setDescColor(int descColor) { - this.descColor = descColor; - return this; - } - - public Drawable getIcon() { - return icon; - } - - public MaterialAboutTitleItem setIcon(Drawable icon) { - this.iconRes = 0; - this.icon = icon; - return this; - } - - public int getIconRes() { - return iconRes; - } - - public MaterialAboutTitleItem setIconRes(int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public MaterialAboutItemOnClickAction getOnClickAction() { - return onClickAction; - } - - public MaterialAboutTitleItem setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - return this; - } - - public MaterialAboutItemOnClickAction getOnLongClickAction() { - return onLongClickAction; - } - - public MaterialAboutTitleItem setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - return this; - } - public static class MaterialAboutTitleItemViewHolder extends MaterialAboutItemViewHolder implements View.OnClickListener, View.OnLongClickListener { - public final View view; - public final ImageView icon; - public final TextView text; - public final TextView desc; - private MaterialAboutItemOnClickAction onClickAction; - private MaterialAboutItemOnClickAction onLongClickAction; - - MaterialAboutTitleItemViewHolder(View view) { - super(view); - this.view = view; - icon = (ImageView) view.findViewById(R.id.mal_item_image); - text = (TextView) view.findViewById(R.id.mal_item_text); - desc = (TextView) view.findViewById(R.id.mal_item_desc); - } - - public void setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - if (onClickAction != null) { - view.setOnClickListener(this); - } else { - view.setClickable(false); - } - } - - public void setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - if (onLongClickAction != null) { - view.setOnLongClickListener(this); - } else { - view.setLongClickable(false); - } - } - - @Override - public void onClick(View v) { - if (onClickAction != null) { - onClickAction.onClick(); - } - } - - @Override - public boolean onLongClick(View v) { - if (onLongClickAction != null) { - onLongClickAction.onClick(); - return true; - } - return false; - } - } - - public static class Builder { - - MaterialAboutItemOnClickAction onClickAction = null; - MaterialAboutItemOnClickAction onLongClickAction = null; - private CharSequence text = null; - @StringRes - private int textRes = 0; - private CharSequence desc = null; - @StringRes - private int descRes = 0; - @ColorInt - private int textColor = -1; - @ColorInt - private int descColor = -1; - private Drawable icon = null; - @DrawableRes - private int iconRes = 0; - - public MaterialAboutTitleItem.Builder text(CharSequence text) { - this.text = text; - this.textRes = 0; - return this; - } - - - public MaterialAboutTitleItem.Builder text(@StringRes int text) { - this.textRes = text; - this.text = null; - return this; - } - - public MaterialAboutTitleItem.Builder desc(CharSequence desc) { - this.desc = desc; - this.descRes = 0; - return this; - } - - - public MaterialAboutTitleItem.Builder desc(@StringRes int desc) { - this.descRes = desc; - this.desc = null; - return this; - } - - public MaterialAboutTitleItem.Builder textColor(@ColorInt int textColor) { - this.textColor = textColor; - return this; - } - - public MaterialAboutTitleItem.Builder descColor(@ColorInt int descColor) { - this.descColor = descColor; - return this; - } - - public MaterialAboutTitleItem.Builder icon(Drawable icon) { - this.icon = icon; - this.iconRes = 0; - return this; - } - - - public MaterialAboutTitleItem.Builder icon(@DrawableRes int iconRes) { - this.icon = null; - this.iconRes = iconRes; - return this; - } - - public MaterialAboutTitleItem.Builder setOnClickAction(MaterialAboutItemOnClickAction onClickAction) { - this.onClickAction = onClickAction; - return this; - } - - public MaterialAboutTitleItem.Builder setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) { - this.onLongClickAction = onLongClickAction; - return this; - } - - public MaterialAboutTitleItem build() { - return new MaterialAboutTitleItem(this); - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/model/MaterialAboutCard.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/model/MaterialAboutCard.java deleted file mode 100644 index ecbffb18..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/model/MaterialAboutCard.java +++ /dev/null @@ -1,156 +0,0 @@ -package com.danielstone.materialaboutlibrary.model; - - -import androidx.annotation.ColorInt; -import androidx.annotation.StringRes; -import androidx.annotation.StyleRes; -import androidx.recyclerview.widget.RecyclerView; - -import com.danielstone.materialaboutlibrary.items.MaterialAboutItem; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.UUID; - -public class MaterialAboutCard { - - private String id = "NO-UUID"; - - private CharSequence title = null; - private int titleRes = 0; - - private int titleColor = 0; - private int cardColor = 0; - - private RecyclerView.Adapter customAdapter = null; - private ArrayList items = new ArrayList<>(); - - - private MaterialAboutCard(Builder builder) { - this.id = UUID.randomUUID().toString(); - this.title = builder.title; - this.titleRes = builder.titleRes; - this.titleColor = builder.titleColor; - this.cardColor = builder.cardColor; - this.items = builder.items; - this.customAdapter = builder.customAdapter; - } - - public MaterialAboutCard(CharSequence title, MaterialAboutItem... materialAboutItems) { - this.title = title; - Collections.addAll(items, materialAboutItems); - } - - public MaterialAboutCard(int titleRes, MaterialAboutItem... materialAboutItems) { - this.titleRes = titleRes; - Collections.addAll(items, materialAboutItems); - } - - public CharSequence getTitle() { - return title; - } - - public int getTitleRes() { - return titleRes; - } - - public int getTitleColor() { - return titleColor; - } - - public int getCardColor() { - return cardColor; - } - - public ArrayList getItems() { - return items; - } - - public static class Builder { - private CharSequence title = null; - @StringRes - private int titleRes = 0; - - @ColorInt - private int titleColor = 0; - - @ColorInt - private int cardColor = 0; - - private ArrayList items = new ArrayList<>(); - private RecyclerView.Adapter customAdapter = null; - - public Builder title(CharSequence title) { - this.title = title; - this.titleRes = 0; - return this; - } - - public Builder title(@StringRes int titleRes) { - this.titleRes = titleRes; - this.title = null; - return this; - } - - public Builder titleColor(@ColorInt int color) { - this.titleColor = color; - return this; - } - - public Builder cardColor(@ColorInt int cardColor) { - this.cardColor = cardColor; - return this; - } - - public Builder addItem(MaterialAboutItem item) { - this.items.add(item); - return this; - } - - public Builder customAdapter(RecyclerView.Adapter customAdapter) { - this.customAdapter = customAdapter; - return this; - } - - public MaterialAboutCard build() { - return new MaterialAboutCard(this); - } - } - - public String getId() { - return id; - } - - public RecyclerView.Adapter getCustomAdapter() { - return customAdapter; - } - - @Override - public String toString() { - String result = "MaterialAboutCard{" + - "id='" + id + '\'' + - ", title=" + title + - ", titleRes=" + titleRes + - ", titleColor=" + titleColor + - ", customAdapter=" + customAdapter + - ", cardColor=" + cardColor + '}'; - return result; - } - - public MaterialAboutCard(MaterialAboutCard card) { - this.id = card.getId(); - this.title = card.getTitle(); - this.titleRes = card.getTitleRes(); - this.titleColor = card.getTitleColor(); - this.cardColor = card.getCardColor(); - this.items = new ArrayList<>(); - this.customAdapter = card.getCustomAdapter(); - for (MaterialAboutItem item : card.items) { - this.items.add(item.clone()); - } - } - public MaterialAboutCard clone() { - return new MaterialAboutCard(this); - } - -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/model/MaterialAboutList.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/model/MaterialAboutList.java deleted file mode 100644 index 910dcc53..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/model/MaterialAboutList.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.danielstone.materialaboutlibrary.model; - - -import java.util.ArrayList; -import java.util.Collections; - -public class MaterialAboutList { - - private ArrayList cards = new ArrayList<>(); - - private MaterialAboutList(Builder builder) { - this.cards = builder.cards; - } - - public MaterialAboutList(MaterialAboutCard... materialAboutCards) { - Collections.addAll(cards, materialAboutCards); - } - - public MaterialAboutList addCard(MaterialAboutCard card) { - cards.add(card); - return this; - } - - public MaterialAboutList clearCards(MaterialAboutCard card) { - cards.clear(); - return this; - } - - public ArrayList getCards() { - return cards; - } - - public static class Builder { - private ArrayList cards = new ArrayList<>(); - - public Builder addCard(MaterialAboutCard card) { - this.cards.add(card); - return this; - } - - public MaterialAboutList build() { - return new MaterialAboutList(this); - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/util/DefaultViewTypeManager.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/util/DefaultViewTypeManager.java deleted file mode 100644 index 8097c972..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/util/DefaultViewTypeManager.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.danielstone.materialaboutlibrary.util; - -import android.content.Context; -import android.view.View; - -import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder; -import com.danielstone.materialaboutlibrary.items.MaterialAboutActionItem; -import com.danielstone.materialaboutlibrary.items.MaterialAboutActionSwitchItem; -import com.danielstone.materialaboutlibrary.items.MaterialAboutCheckboxItem; -import com.danielstone.materialaboutlibrary.items.MaterialAboutItem; -import com.danielstone.materialaboutlibrary.items.MaterialAboutProfileItem; -import com.danielstone.materialaboutlibrary.items.MaterialAboutSwitchItem; -import com.danielstone.materialaboutlibrary.items.MaterialAboutTitleItem; - -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemLayout.ACTION_LAYOUT; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemLayout.ACTION_SWITCH_LAYOUT; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemLayout.CHECKBOX_LAYOUT; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemLayout.PROFILE_LAYOUT; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemLayout.SWITCH_LAYOUT; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemLayout.TITLE_LAYOUT; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemType.ACTION_ITEM; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemType.ACTION_SWITCH_ITEM; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemType.CHECKBOX_ITEM; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemType.PROFILE_ITEM; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemType.SWITCH_ITEM; -import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemType.TITLE_ITEM; - -public class DefaultViewTypeManager extends ViewTypeManager { - - public static final class ItemType { - public static final int ACTION_ITEM = ViewTypeManager.ItemType.ACTION_ITEM; - public static final int TITLE_ITEM = ViewTypeManager.ItemType.TITLE_ITEM; - public static final int SWITCH_ITEM = ViewTypeManager.ItemType.SWITCH_ITEM; - public static final int ACTION_SWITCH_ITEM = ViewTypeManager.ItemType.ACTION_SWITCH_ITEM; - public static final int CHECKBOX_ITEM = ViewTypeManager.ItemType.CHECKBOX_ITEM; - public static final int PROFILE_ITEM = ViewTypeManager.ItemType.PROFILE_ITEM; - } - - public static final class ItemLayout { - public static final int ACTION_LAYOUT = ViewTypeManager.ItemLayout.ACTION_LAYOUT; - public static final int TITLE_LAYOUT = ViewTypeManager.ItemLayout.TITLE_LAYOUT; - public static final int SWITCH_LAYOUT = ViewTypeManager.ItemLayout.SWITCH_LAYOUT; - public static final int ACTION_SWITCH_LAYOUT = ViewTypeManager.ItemLayout.ACTION_SWITCH_LAYOUT; - public static final int CHECKBOX_LAYOUT = ViewTypeManager.ItemLayout.CHECKBOX_LAYOUT; - public static final int PROFILE_LAYOUT = ViewTypeManager.ItemLayout.PROFILE_LAYOUT; - } - - public int getLayout(int itemType) { - switch (itemType) { - case ACTION_ITEM: - return ACTION_LAYOUT; - case TITLE_ITEM: - return TITLE_LAYOUT; - case SWITCH_ITEM: - return SWITCH_LAYOUT; - case ACTION_SWITCH_ITEM: - return ACTION_SWITCH_LAYOUT; - case CHECKBOX_ITEM: - return CHECKBOX_LAYOUT; - case PROFILE_ITEM: - return PROFILE_LAYOUT; - default: - return -1; - } - } - - public MaterialAboutItemViewHolder getViewHolder(int itemType, View view) { - switch (itemType) { - case ACTION_ITEM: - return MaterialAboutActionItem.getViewHolder(view); - case TITLE_ITEM: - return MaterialAboutTitleItem.getViewHolder(view); - case SWITCH_ITEM: - return MaterialAboutSwitchItem.getViewHolder(view); - case ACTION_SWITCH_ITEM: - return MaterialAboutActionSwitchItem.getViewHolder(view); - case CHECKBOX_ITEM: - return MaterialAboutCheckboxItem.getViewHolder(view); - case PROFILE_ITEM: - return MaterialAboutProfileItem.getViewHolder(view); - default: - return null; - } - } - - public void setupItem(int itemType, MaterialAboutItemViewHolder holder, MaterialAboutItem item, Context context) { - switch (itemType) { - case ACTION_ITEM: - MaterialAboutActionItem.setupItem((MaterialAboutActionItem.MaterialAboutActionItemViewHolder) holder, (MaterialAboutActionItem) item, context); - break; - case TITLE_ITEM: - MaterialAboutTitleItem.setupItem((MaterialAboutTitleItem.MaterialAboutTitleItemViewHolder) holder, (MaterialAboutTitleItem) item, context); - break; - case SWITCH_ITEM: - MaterialAboutSwitchItem.setupItem((MaterialAboutSwitchItem.MaterialAboutSwitchItemViewHolder) holder, (MaterialAboutSwitchItem) item, context); - break; - case ACTION_SWITCH_ITEM: - MaterialAboutActionSwitchItem.setupItem((MaterialAboutActionSwitchItem.MaterialAboutActionSwitchItemViewHolder) holder, (MaterialAboutActionSwitchItem) item, context); - break; - case CHECKBOX_ITEM: - MaterialAboutCheckboxItem.setupItem((MaterialAboutCheckboxItem.MaterialAboutCheckboxItemViewHolder) holder, (MaterialAboutCheckboxItem) item, context); - break; - case PROFILE_ITEM: - MaterialAboutProfileItem.setupItem((MaterialAboutProfileItem.MaterialAboutProfileItemViewHolder) holder, (MaterialAboutProfileItem) item, context); - break; - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/util/OpenSourceLicense.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/util/OpenSourceLicense.java deleted file mode 100644 index c916b2b6..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/util/OpenSourceLicense.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.danielstone.materialaboutlibrary.util; - -import com.danielstone.materialaboutlibrary.R; - -public enum OpenSourceLicense { - APACHE_2, MIT, GNU_GPL_3, BSD; - - public int getResourceId() { - switch (this) { - case APACHE_2: - return R.string.license_apache2; - case MIT: - return R.string.license_mit; - case GNU_GPL_3: - return R.string.license_gpl; - case BSD: - return R.string.license_bsd; - default: - return -1; - } - } -} diff --git a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/util/ViewTypeManager.java b/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/util/ViewTypeManager.java deleted file mode 100644 index d496dadd..00000000 --- a/material-about-library/src/main/java/com/danielstone/materialaboutlibrary/util/ViewTypeManager.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.danielstone.materialaboutlibrary.util; - -import android.content.Context; -import android.view.View; - -import com.danielstone.materialaboutlibrary.R; -import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder; -import com.danielstone.materialaboutlibrary.items.MaterialAboutItem; - -public abstract class ViewTypeManager { - - public static final class ItemType { - public static final int ACTION_ITEM = 0; - public static final int TITLE_ITEM = 1; - public static final int SWITCH_ITEM = 2; - public static final int ACTION_SWITCH_ITEM = 3; - public static final int CHECKBOX_ITEM = 4; - public static final int PROFILE_ITEM = 5; - } - - public static final class ItemLayout { - public static final int ACTION_LAYOUT = R.layout.mal_material_about_action_item; - public static final int TITLE_LAYOUT = R.layout.mal_material_about_title_item; - public static final int SWITCH_LAYOUT = R.layout.mal_material_about_switch_item; - public static final int ACTION_SWITCH_LAYOUT = R.layout.mal_material_about_action_switch_item; - public static final int CHECKBOX_LAYOUT = R.layout.mal_material_about_checkbox_item; - public static final int PROFILE_LAYOUT = R.layout.mal_material_about_profile_item; - } - - public abstract int getLayout(int itemType); - - public abstract MaterialAboutItemViewHolder getViewHolder(int itemType, View view); - - public abstract void setupItem(int itemType, MaterialAboutItemViewHolder holder, MaterialAboutItem item, Context context); -} diff --git a/material-about-library/src/main/res/layout/mal_material_about_action_item.xml b/material-about-library/src/main/res/layout/mal_material_about_action_item.xml deleted file mode 100644 index 5edc81d4..00000000 --- a/material-about-library/src/main/res/layout/mal_material_about_action_item.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/layout/mal_material_about_action_switch_item.xml b/material-about-library/src/main/res/layout/mal_material_about_action_switch_item.xml deleted file mode 100644 index 9e1dd978..00000000 --- a/material-about-library/src/main/res/layout/mal_material_about_action_switch_item.xml +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/layout/mal_material_about_activity.xml b/material-about-library/src/main/res/layout/mal_material_about_activity.xml deleted file mode 100644 index 42f77361..00000000 --- a/material-about-library/src/main/res/layout/mal_material_about_activity.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - diff --git a/material-about-library/src/main/res/layout/mal_material_about_checkbox_item.xml b/material-about-library/src/main/res/layout/mal_material_about_checkbox_item.xml deleted file mode 100644 index 659bbd1f..00000000 --- a/material-about-library/src/main/res/layout/mal_material_about_checkbox_item.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/layout/mal_material_about_fragment.xml b/material-about-library/src/main/res/layout/mal_material_about_fragment.xml deleted file mode 100644 index f8bdb8e0..00000000 --- a/material-about-library/src/main/res/layout/mal_material_about_fragment.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/layout/mal_material_about_list_card.xml b/material-about-library/src/main/res/layout/mal_material_about_list_card.xml deleted file mode 100644 index 0d1f73e8..00000000 --- a/material-about-library/src/main/res/layout/mal_material_about_list_card.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/layout/mal_material_about_profile_item.xml b/material-about-library/src/main/res/layout/mal_material_about_profile_item.xml deleted file mode 100644 index a90ccba1..00000000 --- a/material-about-library/src/main/res/layout/mal_material_about_profile_item.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/layout/mal_material_about_switch_item.xml b/material-about-library/src/main/res/layout/mal_material_about_switch_item.xml deleted file mode 100644 index b888bc0f..00000000 --- a/material-about-library/src/main/res/layout/mal_material_about_switch_item.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/layout/mal_material_about_title_item.xml b/material-about-library/src/main/res/layout/mal_material_about_title_item.xml deleted file mode 100644 index e77e04c8..00000000 --- a/material-about-library/src/main/res/layout/mal_material_about_title_item.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/values/attrs.xml b/material-about-library/src/main/res/values/attrs.xml deleted file mode 100644 index 9d555688..00000000 --- a/material-about-library/src/main/res/values/attrs.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/values/colors.xml b/material-about-library/src/main/res/values/colors.xml deleted file mode 100644 index 057f6cb3..00000000 --- a/material-about-library/src/main/res/values/colors.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - #de000000 - #8a000000 - - #ff9b9b9b - \ No newline at end of file diff --git a/material-about-library/src/main/res/values/dimens.xml b/material-about-library/src/main/res/values/dimens.xml deleted file mode 100644 index 06796bac..00000000 --- a/material-about-library/src/main/res/values/dimens.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - 16dp - 8dp - - 24dp - 32dp - 40dp - - 4dp - 4dp - - - \ No newline at end of file diff --git a/material-about-library/src/main/res/values/strings.xml b/material-about-library/src/main/res/values/strings.xml deleted file mode 100644 index cbe49a18..00000000 --- a/material-about-library/src/main/res/values/strings.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - About - - Close - Send email - - No apps to handle action - - - "\nCopyright %1$s %2$s\n" - - "\nLicensed under the Apache License, Version 2.0 (the \"License\");" - "you may not use this file except in compliance with the License." - "You may obtain a copy of the License at\n" - - "\nhttp://www.apache.org/licenses/LICENSE-2.0\n" - - "\nUnless required by applicable law or agreed to in writing, software" - "distributed under the License is distributed on an \"AS IS\" BASIS," - "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." - "See the License for the specific language governing permissions and" - "limitations under the License." - - - - "\nMIT License\n" - - "\nCopyright © %1$s %2$s\n" - - "\nPermission is hereby granted, free of charge, to any person obtaining a copy" - "of this software and associated documentation files (the "Software"), to deal" - "in the Software without restriction, including without limitation the rights" - "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell" - "copies of the Software, and to permit persons to whom the Software is" - "furnished to do so, subject to the following conditions:\n" - - "\nThe above copyright notice and this permission notice shall be included in all" - "copies or substantial portions of the Software.\n" - - "\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR" - "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY," - "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE" - "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER" - "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM," - "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE" - "SOFTWARE." - - - - "\nCopyright © %1$s %2$s\n" - - "\nThis program is free software: you can redistribute it and/or modify" - "it under the terms of the GNU General Public License as published by" - "the Free Software Foundation, either version 3 of the License, or" - "(at your option) any later version.\n" - - "\nThis program is distributed in the hope that it will be useful," - "but WITHOUT ANY WARRANTY; without even the implied warranty of" - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" - "GNU General Public License for more details.\n" - - "\nYou should have received a copy of the GNU General Public License" - "along with this program. If not, see http://www.gnu.org/licenses.\n" - - - - "\nCopyright © %1$s %2$s\n" - - "\nRedistribution and use in source and binary forms, with or without" - "modification, are permitted provided that the following conditions are met:\n" - - "\n1. Redistributions of source code must retain the above copyright notice, this" - " list of conditions and the following disclaimer.\n" - "2. Redistributions in binary form must reproduce the above copyright notice," - " this list of conditions and the following disclaimer in the documentation" - " and/or other materials provided with the distribution.\n" - - "\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND" - "ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED" - "WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE" - "DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR" - "ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES" - "(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;" - "LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND" - "ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT" - "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS" - "SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" - - "\nThe views and conclusions contained in the software and documentation are those" - "of the authors and should not be interpreted as representing official policies," - "either expressed or implied, of the FreeBSD Project.\n" - - diff --git a/material-about-library/src/main/res/values/styles.xml b/material-about-library/src/main/res/values/styles.xml deleted file mode 100644 index d0c6188b..00000000 --- a/material-about-library/src/main/res/values/styles.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - -