Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3d2bb87a authored by Joey's avatar Joey
Browse files

Initial implementation



Signed-off-by: default avatarJoey <joey@lineageos.org>
parent fdd18e19
Loading
Loading
Loading
Loading

app/.gitignore

0 → 100644
+1 −0
Original line number Diff line number Diff line
/build

app/build.gradle

0 → 100644
+53 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The LineageOS Project
 *
 * Licensed 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
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless 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.
 */

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28

    defaultConfig {
        applicationId "org.lineageos.backgrounds"
        minSdkVersion 27
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    sourceSets {
        main {
            res.srcDirs = ['src/main/res', 'src/main/res_1080p']
        }
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.palette:palette:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
}

app/proguard-rules.pro

0 → 100644
+21 −0
Original line number Diff line number Diff line
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
+49 −0
Original line number Diff line number Diff line
<!--
  Copyright (C) 2019 The LineageOS Project

  Licensed 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

       http://www.apache.org/licenses/LICENSE-2.0

  Unless 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.
  -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="org.lineageos.backgrounds">

    <uses-permission android:name="android.permission.SET_WALLPAPER" />

    <application
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="GoogleAppIndexingWarning">

        <activity android:name=".ui.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".ui.ApplyActivity" />

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="org.lineageos.backgrounds.files"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths" />
        </provider>
    </application>
</manifest>
+97 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The LineageOS Project
 *
 * Licensed 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
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless 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.
 */
package org.lineageos.backgrounds.adapters;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;

import org.lineageos.backgrounds.R;
import org.lineageos.backgrounds.bundle.WallpaperBundle;
import org.lineageos.backgrounds.bundle.WallpaperType;
import org.lineageos.backgrounds.holders.UserHolder;
import org.lineageos.backgrounds.holders.WallpaperHolder;
import org.lineageos.backgrounds.ui.SelectionInterface;
import org.lineageos.backgrounds.util.TypeConverter;

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

public final class WallsAdapter extends RecyclerView.Adapter<WallpaperHolder> {
    private final SelectionInterface mCallback;
    private List<WallpaperBundle> mData = new ArrayList<>();

    public WallsAdapter(@NonNull final SelectionInterface callback) {
        mCallback = callback;
    }

    @NonNull
    @Override
    public WallpaperHolder onCreateViewHolder(@NonNull final ViewGroup parent,
                                              final int viewType) {
        final WallpaperType type = TypeConverter.intToWallpaperType(viewType);

        switch (type) {
            case BUILT_IN:
            case DEFAULT:
            case MONO:
                return buildDefaultHolder(parent);
            default:
                return buildUserHolder(parent);
        }
    }

    @Override
    public void onBindViewHolder(final @NonNull WallpaperHolder holder, final int position) {
        final WallpaperBundle bundle = mData.get(position);
        holder.bind(bundle);
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    @Override
    public int getItemViewType(final int position) {
        return TypeConverter.wallpaperTypeToInt(mData.get(position).getType());
    }

    public void setData(final List<WallpaperBundle> data) {
        final WallsDiffCallback callback = new WallsDiffCallback(mData, data);
        DiffUtil.calculateDiff(callback).dispatchUpdatesTo(this);
        mData = data;
    }

    // Reified generics when java?

    @NonNull
    private WallpaperHolder buildDefaultHolder(@NonNull final ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        return new WallpaperHolder(inflater.inflate(R.layout.item_wallpaper,
                parent, false), mCallback);
    }

    @NonNull
    private UserHolder buildUserHolder(@NonNull final ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        return new UserHolder(inflater.inflate(R.layout.item_wallpaper,
                parent, false), mCallback);
    }
}
Loading