Skip to content

Commit

Permalink
Android Res Links
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed Jun 13, 2021
1 parent 3fcc001 commit eae8285
Show file tree
Hide file tree
Showing 133 changed files with 667 additions and 206 deletions.
2 changes: 1 addition & 1 deletion SteamToolsV2+.sln
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ST.Client.Mobile.iOS.App",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bin", "src\ST.Client.Desktop.Avalonia.App.Bridge.Package.RefLauncher\Bin\Bin.csproj", "{AC8E40AE-CED2-415A-BC47-A68F3F14CB09}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ST.Tools.AndroidResourceLink", "src\ST.Tools.AndroidResourceLink\ST.Tools.AndroidResourceLink.csproj", "{9A8D2254-9B2B-4B92-8498-43A73BB9A410}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ST.Tools.AndroidResourceLink", "src\ST.Tools.AndroidResourceLink\ST.Tools.AndroidResourceLink.csproj", "{9A8D2254-9B2B-4B92-8498-43A73BB9A410}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
107 changes: 107 additions & 0 deletions src/LayoutBinding.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System;

using Android.App;
using Android.Views;

namespace Xamarin.Android.Design
{
public delegate Java.Lang.Object OnLayoutItemNotFoundHandler(int resourceId, Type expectedViewType);

abstract class LayoutBinding
{
Activity boundActivity;
View boundView;
OnLayoutItemNotFoundHandler onLayoutItemNotFound;

protected LayoutBinding(Activity activity, OnLayoutItemNotFoundHandler onLayoutItemNotFound = null)
{
boundActivity = activity ?? throw new ArgumentNullException(nameof(activity));
this.onLayoutItemNotFound = onLayoutItemNotFound;
}

protected LayoutBinding(View view, OnLayoutItemNotFoundHandler onLayoutItemNotFound = null)
{
boundView = view ?? throw new ArgumentNullException(nameof(view));
this.onLayoutItemNotFound = onLayoutItemNotFound;
}

protected T FindView<T>(int resourceId, ref T cachedField) where T : View
{
if (cachedField != null)
return cachedField;

T ret;
if (boundActivity != null)
ret = boundActivity.FindViewById<T>(resourceId);
else
ret = boundView.FindViewById<T>(resourceId);

if (ret == null && onLayoutItemNotFound != null)
ret = (T)onLayoutItemNotFound(resourceId, typeof(T));

if (ret == null)
throw new global::System.InvalidOperationException($"View not found (Resource ID: {resourceId})");

cachedField = ret;
return ret;
}

Activity EnsureActivity()
{
if (boundActivity != null)
return boundActivity;

var ret = boundView?.Context as Activity;
if (ret != null)
return ret;

throw new InvalidOperationException("Finding fragments is supported only for Activity instances");
}

T __FindFragment<T>(int resourceId, Func<Activity, T> finder, ref T cachedField) where T : Java.Lang.Object
{
if (cachedField != null)
return cachedField;

var ret = finder(EnsureActivity());
if (ret == null && onLayoutItemNotFound != null)
ret = (T)onLayoutItemNotFound(resourceId, typeof(T));

if (ret == null)
throw new InvalidOperationException($"Fragment not found (ID: {resourceId}; Type: {typeof(T)})");

cachedField = ret;
return ret;
}
#if __ANDROID_11__
//protected T FindFragment<T>(int resourceId, global::Android.App.Fragment __ignoreMe, ref T cachedField) where T : global::Android.App.Fragment
//{
// return __FindFragment<T>(resourceId, (activity) => activity.FragmentManager.FindFragmentById<T>(resourceId), ref cachedField);
//}
#endif // __ANDROID_11__

#if __HAVE_SUPPORT__
protected T FindFragment <T> (int resourceId, global::Android.Support.V4.App.Fragment __ignoreMe, ref T cachedField) where T: global::Android.Support.V4.App.Fragment
{
return __FindFragment<T> (resourceId, (activity) => activity.FragmentManager.FindFragmentById<T> (resourceId), ref cachedField);
}
#endif // __HAVE_SUPPORT__

#if __HAVE_ANDROIDX__
protected T FindFragment<T>(int resourceId, global::AndroidX.Fragment.App.Fragment __ignoreMe, ref T cachedField) where T : global::AndroidX.Fragment.App.Fragment
{
return __FindFragment(resourceId, (activity) =>
{
if (activity is AndroidX.AppCompat.App.AppCompatActivity activity_)
{
return global::Android.Runtime.Extensions.JavaCast<T>(activity_.SupportFragmentManager.FindFragmentById(resourceId));
}
else
{
throw new InvalidCastException(activity.GetType().ToString());
}
}, ref cachedField);
}
#endif // __HAVE_ANDROIDX__
}
}
1 change: 1 addition & 0 deletions src/ST.Client.Mobile.Droid.Design/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies {
implementation 'androidx.navigation:navigation-ui:2.3.5'
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha05'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation project(path: ':ui')
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
android:name=".ui.activities.MainActivity"
android:configChanges="screenSize|orientation|keyboard|keyboardHidden|screenLayout|smallestScreenSize"
android:label="@string/app_name"
android:launchMode="singleInstance" />
android:launchMode="singleTask" />
<activity
android:name=".ui.activities.SplashActivity"
android:configChanges="screenSize|orientation|keyboard|keyboardHidden|screenLayout|smallestScreenSize"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:launchMode="singleTask"
android:noHistory="true"
android:theme="@style/MainTheme.Splash">
<intent-filter>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import androidx.navigation.ui.NavigationUI;

import net.steampp.app.design.R;
import net.steampp.app.design.databinding.ActivityMainBinding;
import net.steampp.app.ui.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import net.steampp.app.design.databinding.FragmentCommunityFixBinding;
import net.steampp.app.ui.databinding.FragmentCommunityFixBinding;
import net.steampp.app.design.ui.viewmodels.CommunityFixViewModel;

public class CommunityFixFragment extends Fragment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import net.steampp.app.design.databinding.FragmentGameListBinding;
import net.steampp.app.ui.databinding.FragmentGameListBinding;
import net.steampp.app.design.ui.viewmodels.GameListViewModel;

public class GameListFragment extends Fragment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import net.steampp.app.design.databinding.FragmentLocalAuthBinding;
import net.steampp.app.ui.databinding.FragmentLocalAuthBinding;
import net.steampp.app.design.ui.viewmodels.LocalAuthViewModel;

public class LocalAuthFragment extends Fragment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import net.steampp.app.design.databinding.FragmentMyBinding;
import net.steampp.app.ui.databinding.FragmentMyBinding;
import net.steampp.app.design.ui.viewmodels.MyViewModel;

public class MyFragment extends Fragment {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
<resources>
<string name="local_auth">本地令牌</string>
<string name="my">我的</string>
<string name="community_fix">社区加速</string>
<string name="game_list">库存游戏</string>
<string name="under_construction">该功能正在开发中,敬请期待</string>
<string name="login_and_register">登录 / 注册</string>
<string name="settings">设置</string>
<string name="edit_profile">编辑资料</string>
<string name="app_name">Steam++(Design)</string>
</resources>

This file was deleted.

2 changes: 2 additions & 0 deletions src/ST.Client.Mobile.Droid.Design/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
rootProject.name = "Steam++"
include ':app'
include ':ui'
include ':ui'
1 change: 1 addition & 0 deletions src/ST.Client.Mobile.Droid.Design/ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
50 changes: 50 additions & 0 deletions src/ST.Client.Mobile.Droid.Design/ui/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
plugins {
id 'com.android.library'
}

android {
compileSdkVersion 30

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
lintOptions {
abortOnError false
}
}

dependencies {
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'androidx.navigation:navigation-fragment:2.3.5'
implementation 'androidx.navigation:navigation-ui:2.3.5'
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha05'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
Empty file.
21 changes: 21 additions & 0 deletions src/ST.Client.Mobile.Droid.Design/ui/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.steampp.app.ui;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("net.steampp.app.ui.test", appContext.getPackageName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.steampp.app.ui">

</manifest>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
xmlns:xamarin="http://schemas.xamarin.com/android/xamarin/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand All @@ -16,7 +16,8 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />
app:menu="@menu/bottom_nav_menu"
xamarin:managedType="Google.Android.Material.BottomNavigation.BottomNavigationView" />

<fragment
android:id="@+id/nav_host_fragment_activity_main"
Expand All @@ -28,6 +29,7 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation" />
app:navGraph="@navigation/mobile_navigation"
xamarin:managedType="AndroidX.Navigation.Fragment.NavHostFragment" />

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:xamarin="http://schemas.xamarin.com/android/xamarin/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.fragments.CommunityFixFragment">
android:layout_height="match_parent">

<TextView
android:id="@+id/textView"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:xamarin="http://schemas.xamarin.com/android/xamarin/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.fragments.GameListFragment">
android:layout_height="match_parent">

<TextView
android:id="@+id/textView"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:xamarin="http://schemas.xamarin.com/android/xamarin/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.fragments.LocalAuthFragment">
android:layout_height="match_parent">

<TextView
android:id="@+id/textView"
Expand Down
Loading

0 comments on commit eae8285

Please sign in to comment.