Browse Source

INEFFICIENT: First attempts to break dynamic linear layouts & Kotlin configuration

master^2
Janis 6 months ago
parent
commit
42ba9eb673
6 changed files with 72 additions and 63 deletions
  1. +3
    -0
      app/build.gradle
  2. +18
    -1
      app/src/main/java/app/pott/kaffeepott/androidclient/core/Badge.java
  3. +1
    -10
      app/src/main/java/app/pott/kaffeepott/androidclient/ui/BadgeFragment.java
  4. +29
    -33
      app/src/main/res/layout/fragment_badge.xml
  5. +17
    -17
      app/src/main/res/layout/fragment_cafe_item.xml
  6. +4
    -2
      build.gradle

+ 3
- 0
app/build.gradle View File

@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 29
@@ -51,4 +52,6 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.1.0'
implementation "androidx.core:core-ktx:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

+ 18
- 1
app/src/main/java/app/pott/kaffeepott/androidclient/core/Badge.java View File

@@ -1,10 +1,17 @@
package app.pott.kaffeepott.androidclient.core;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.DrawableRes;
import androidx.annotation.StringRes;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import app.pott.kaffeepott.androidclient.ui.R;
@@ -16,6 +23,7 @@ import app.pott.kaffeepott.androidclient.ui.R;
* @author Janis Bailitis
* @author Linus Mathieu
*/
@SuppressLint("StaticFieldLeak")
public enum Badge {
/**
* Given if the café has WiFi-access. By now, it is not distinguished between free and paid
@@ -77,6 +85,7 @@ public enum Badge {
private @StringRes
int displayTextId;
private boolean addable;
private View view;

Badge(int iconId, int displayTextId) {
this(iconId, displayTextId, true);
@@ -98,6 +107,14 @@ public enum Badge {
return displayTextId;
}

public View getView(LayoutInflater inflater, ViewGroup root, Context context) {
view = inflater.inflate(R.layout.fragment_badge, root, false);
((ImageView) view.findViewById(R.id.badgeFragmentImageView)).setImageResource(iconId);
((TextView) view.findViewById(R.id.badgeFragmentTextView)).setText(context.getString(displayTextId));

return view;
}

public static Badge[] addableValues() {
List<Badge> retVal = new ArrayList<>();
for (Badge badge : values())


+ 1
- 10
app/src/main/java/app/pott/kaffeepott/androidclient/ui/BadgeFragment.java View File

@@ -58,16 +58,7 @@ public class BadgeFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
root = inflater.inflate(R.layout.fragment_badge, container, false);

Badge badge = Enum.valueOf(Badge.class, badgeName);

ImageView badgeImageView = root.findViewById(R.id.badgeFragmentImageView);
badgeImageView.setImageResource(badge.getIconId());

TextView badgeTextView = root.findViewById(R.id.badgeFragmentTextView);

badgeTextView.setText(getString(badge.getDisplayTextId()));
root = Badge.valueOf(badgeName).getView(inflater, container, getContext());

setCollapsed(collapsed);



+ 29
- 33
app/src/main/res/layout/fragment_badge.xml View File

@@ -1,43 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".BadgeFragment"
>

<LinearLayout
android:id="@+id/badgeFragmentLinearLayout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="end"
android:orientation="horizontal"
android:padding="2dp"
android:paddingStart="0dp"
android:paddingEnd="4dp"
>
android:layout_height="wrap_content"
tools:context=".BadgeFragment">

<ImageView
android:id="@+id/badgeFragmentImageView"
<LinearLayout
android:id="@+id/badgeFragmentLinearLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/rounded_corners_start_shape"
android:padding="4dp"
android:src="@drawable/ic_network_wifi"
/>
android:gravity="end"
android:orientation="horizontal"
android:padding="2dp"
android:paddingStart="0dp"
android:paddingEnd="4dp">

<ImageView
android:id="@+id/badgeFragmentImageView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/rounded_corners_start_shape"
android:padding="4dp"
android:src="@drawable/ic_network_wifi" />

<TextView
android:id="@+id/badgeFragmentTextView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/rounded_corners_end_shape"
android:gravity="center_vertical"
android:lines="1"
android:paddingStart="0dp"
android:paddingEnd="6dp"
android:text="dfshdfgbs"
android:textColor="@color/colorForeground"
android:textSize="@dimen/h3"
/>
android:id="@+id/badgeFragmentTextView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/rounded_corners_end_shape"
android:gravity="center_vertical"
android:lines="1"
android:paddingStart="0dp"
android:paddingEnd="6dp"
android:text="dfshdfgbs"
android:textColor="@color/colorForeground"
android:textSize="@dimen/h3" />
</LinearLayout>
</FrameLayout>

+ 17
- 17
app/src/main/res/layout/fragment_cafe_item.xml View File

@@ -138,25 +138,25 @@
</androidx.constraintlayout.widget.ConstraintLayout>

<HorizontalScrollView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/cafeFragmentSecondLineCL"
app:layout_constraintTop_toBottomOf="@+id/cafeFragmentSecondLineCL"
>
android:id="@+id/horizontalScrollView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/cafeFragmentSecondLineCL"
app:layout_constraintTop_toBottomOf="@+id/cafeFragmentSecondLineCL">

<FrameLayout
android:id="@+id/cafeFragmentBadgeFragmentStandalone"
android:layout_width="wrap_content"
android:layout_height="28dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout="@layout/fragment_badges"
/>
android:id="@+id/cafeFragmentBadgeFragmentStandalone"
android:layout_width="wrap_content"
android:layout_height="28dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout="@layout/fragment_badges" />
</HorizontalScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

+ 4
- 2
build.gradle View File

@@ -1,7 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.72'

repositories {
google()
jcenter()
@@ -9,7 +10,8 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"


// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files


Loading…
Cancel
Save