Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
In my mind, 🍺 in my heart

Tomasz tmaxxdd

💻
In my mind, 🍺 in my heart
View GitHub Profile
View product_with_type_converter.java
@Entity
public class Product {
// productId, name, price, @Ignore image
@TypeConverters(value = SQLTypeConverters.class)
@ColumnInfo(defaultValue = "CURRENT_TIMESTAMP")
public Date timestamp;
public Product(long productId, String name, double price) {
this.productId = productId;
this.name = name;
View type_converters.java
public class SQLTypeConverters {
@TypeConverter
public Date fromTimestamp(String value) {
Date defaultDate = new Date();
SimpleDateFormat format = new SimpleDateFormat();
try {
return value.equals("") ? defaultDate : format.parse(value);
} catch (ParseException e) {
e.printStackTrace();
View product.java
@Entity
public class Product {
// ... productId, name, price, @Ignore image
@ColumnInfo(defaultValue = "CURRENT_TIMESTAMP")
public String timestamp;
public Product(long productId, String name, double price) {
this.productId = productId;
this.name = name;
this.price = price;
View desctructive.java
Room
.databaseBuilder(this, Database.class, "database")
.addMigrations(Migrations.MIGRATION_1_2)
.fallbackToDestructiveMigration()
.build();
View db.java
Room
.databaseBuilder(this, Database.class, "database")
.addMigrations(Migrations.MIGRATION_1_2)
.build();
View migration_class.java
public class Migrations {
public static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE user ADD COLUMN professionOwnerId INTEGER NOT NULL DEFAULT 1");
}
};
}
View ml_logcat.cl
V/MotionLayout: CHECK: start is hided
V/MotionLayout: CHECK: end is shown
W/MotionLayout: CHECK: hided NO View matches id itemBackground
W/MotionLayout: CHECK: hided(itemBackground) no LAYOUT_HEIGHT
W/MotionLayout: CHECK: hided NO View matches id dragLabel
W/MotionLayout: CHECK: hided NO View matches id itemForeground
W/MotionLayout: CHECK: hided(itemForeground) no LAYOUT_HEIGHT
W/MotionLayout: CHECK: hided NO View matches id deleteAction
V/MotionLayout: CHECK: CURRENT
V/MotionLayout: CHECK: transition = hided -> shown
View first_transition.xml
<!-- This is applied for default -->
<Transition
app:constraintSetEnd="@id/panelExpanded"
app:constraintSetStart="@id/panelCollapsed"
app:duration="500">
<OnSwipe app:dragDirection="dragRight" />
</Transition>
<!-- This must be set explicitly from code or xml -->
<Transition
View derive_constraints.xml
<MotionScene>
<!-- You must implement all the attributes -->
<ConstraintSet android:id="@+id/viewsInvisible">
<Constraint android:id="@+id/loading">
<Layout
android:layout_width="64dp"
android:layout_height="64dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
View bs_switch.kt
bottomSheetSwitch.setOnCheckedChangeListener { _, bottomSheetSmall ->
if (bottomSheetSmall)
motionLayout.loadLayoutDescription(R.xml.expandable_bottom_sheet_small)
else
motionLayout.loadLayoutDescription(R.xml.expandable_bottom_sheet_big)
}