Skip to content

Commit

Permalink
[update] 发布1.0.4版本
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMofer committed May 12, 2021
1 parent c000836 commit 399ef83
Show file tree
Hide file tree
Showing 39 changed files with 1,634 additions and 26 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'io.github.alexmofer.appcompat:appcompat:1.2.0'
implementation 'io.github.alexmofer.job:job-android:1.0.0'
implementation project(':opentype')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.am.font.ui">

<application
android:name=".UIApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.OpenType">
<activity android:name=".MainActivity">
android:theme="@style/Theme.OpenType"
tools:ignore="AllowBackup">
<activity
android:name=".main.MainActivity"
android:theme="@style/Theme.OpenType.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".opentype.OpenTypeActivity"
android:theme="@style/Theme.OpenType.NoActionBar" />
</application>

</manifest>
14 changes: 0 additions & 14 deletions app/src/main/java/com/am/font/ui/MainActivity.java

This file was deleted.

20 changes: 20 additions & 0 deletions app/src/main/java/com/am/font/ui/UIApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.am.font.ui;

import android.app.Application;

import com.am.appcompat.app.ApplicationHolder;

public class UIApplication extends Application {

@Override
public void onCreate() {
super.onCreate();
ApplicationHolder.create(this);
}

@Override
public void onTerminate() {
super.onTerminate();
ApplicationHolder.destroy(this);
}
}
138 changes: 138 additions & 0 deletions app/src/main/java/com/am/font/ui/common/LoadingActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/* ###WS@M Project:PDFelement-Android ### */
package com.am.font.ui.common;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;

import com.am.appcompat.app.AppCompatActivity;
import com.am.appcompat.app.AppCompatDialogFragment;
import com.am.font.ui.R;

/**
* 带载入状态的Activity
* Created by Xiang Zhicheng on 2021/4/27.
*/
public abstract class LoadingActivity extends AppCompatActivity {

private static final String TAG_LOADING = "LoadingActivity.TAG_LOADING";
private boolean mLoading = false;

public LoadingActivity() {
}

public LoadingActivity(int contentLayoutId) {
super(contentLayoutId);
}

/**
* 显示载入对话框
*/
public void showLoading(@Nullable String message) {
if (mLoading)
return;
mLoading = true;
final FragmentManager manager = getSupportFragmentManager();
final Fragment fragment = manager.findFragmentByTag(TAG_LOADING);
if (fragment instanceof InnerLoadingDialogFragment)
return;
InnerLoadingDialogFragment.newInstance(message).show(manager, TAG_LOADING);
}

/**
* 显示载入对话框
*/
public void showLoading(@StringRes int message) {
showLoading(getString(message));
}

/**
* 显示载入对话框
*/
public void showLoading() {
showLoading(null);
}

/**
* 关闭载入对话框
*/
public void dismissLoading() {
if (!mLoading)
return;
mLoading = false;
final FragmentManager manager = getSupportFragmentManager();
final Fragment fragment = manager.findFragmentByTag(TAG_LOADING);
if (fragment instanceof InnerLoadingDialogFragment)
((InnerLoadingDialogFragment) fragment).dismissAllowingStateLoss();
}

/**
* 延迟关闭对话框
*
* @param delayMillis 延迟时间
*/
public void postDelayedDismissLoading(long delayMillis) {
getWindow().getDecorView().postDelayed(this::dismissLoading, delayMillis);
}

/**
* 判断是否正在显示载入对话框
*
* @return 正在显示载入对话框时返回true
*/
public boolean isLoading() {
return mLoading;
}

/**
* 内部载入对话框Fragment
*/
public static final class InnerLoadingDialogFragment extends AppCompatDialogFragment {

private static final String KEY_MESSAGE = "message";

public InnerLoadingDialogFragment() {
super(R.layout.dlg_common_loading);
setStyle(STYLE_NO_TITLE, R.style.Style_OpenType_Dialog_Transparent);
}

public static InnerLoadingDialogFragment newInstance(@Nullable String message) {
final InnerLoadingDialogFragment fragment = new InnerLoadingDialogFragment();
final Bundle args = new Bundle();
args.putString(KEY_MESSAGE, message);
fragment.setArguments(args);
return fragment;
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setCancelable(false);
requireDialog().setCanceledOnTouchOutside(false);
// final Bundle args = getArguments();
// if (args != null) {
// final String message = args.getString(KEY_MESSAGE);
// if (message != null) {
// view.findViewById(R.id.mcl_iv_image).setBackgroundColor(Color.TRANSPARENT);
// final TextView text = view.findViewById(R.id.dcl_tv_message);
// text.setText(message);
// view.setBackgroundResource(R.drawable.bg_common_loading_message);
// }
// }
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final FragmentActivity activity = getActivity();
if (activity instanceof LoadingActivity && !((LoadingActivity) activity).isLoading())
dismissAllowingStateLoss();
}
}
}
53 changes: 53 additions & 0 deletions app/src/main/java/com/am/font/ui/main/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.am.font.ui.main;

import android.graphics.drawable.Drawable;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.RecyclerView;

import com.am.appcompat.app.AppCompatActivity;
import com.am.font.ui.R;
import com.am.font.ui.opentype.OpenTypeActivity;

public class MainActivity extends AppCompatActivity implements MainView,
MainViewHolder.OnViewHolderListener {

private final MainPresenter mPresenter =
new MainPresenter().setViewHolder(getViewHolder());
private final MainAdapter mAdapter = new MainAdapter(mPresenter, this);

public MainActivity() {
super(R.layout.activity_main);
}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final RecyclerView list = findViewById(R.id.otl_content);
final Drawable divider = ContextCompat.getDrawable(this, R.drawable.divider_common);
if (divider != null) {
final DividerItemDecoration decoration = new DividerItemDecoration(list.getContext(),
DividerItemDecoration.VERTICAL);
decoration.setDrawable(divider);
list.addItemDecoration(decoration);
}

list.setAdapter(mAdapter);
mPresenter.loadOpenType();
}

// View
@Override
public void onOpenTypeLoaded() {
mAdapter.notifyDataSetChanged();
}

// Listener
@Override
public void onItemClick(Object item) {
OpenTypeActivity.start(this, mPresenter.getItemPath(item));
}
}
52 changes: 52 additions & 0 deletions app/src/main/java/com/am/font/ui/main/MainAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2018 AlexMofer
*
* 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 com.am.font.ui.main;

import android.view.ViewGroup;

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

/**
* Adapter
*/
class MainAdapter extends RecyclerView.Adapter<MainViewHolder> {

private final MainDataAdapter mAdapter;
private final MainViewHolder.OnViewHolderListener mListener;

MainAdapter(MainDataAdapter adapter,
MainViewHolder.OnViewHolderListener listener) {
mAdapter = adapter;
mListener = listener;
}

@NonNull
@Override
public MainViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int position) {
return new MainViewHolder(parent, mListener);
}

@Override
public void onBindViewHolder(@NonNull MainViewHolder holder, int position) {
holder.bind(position, mAdapter);
}

@Override
public int getItemCount() {
return mAdapter.getItemCount();
}
}
31 changes: 31 additions & 0 deletions app/src/main/java/com/am/font/ui/main/MainDataAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2018 AlexMofer
*
* 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 com.am.font.ui.main;

/**
* AdapterViewModel
*/
interface MainDataAdapter {
int getItemCount();

Object getItem(int position);

String getItemName(Object item);

void loadOpenType();

String getItemPath(Object item);
}
Loading

0 comments on commit 399ef83

Please sign in to comment.