Skip to content

Commit

Permalink
update for v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
RichadoWonosas committed Apr 19, 2021
1 parent 78f9691 commit dd5dc9c
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 75 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "ap.yadora.richadowonosas.fmdslst"
minSdkVersion 21
targetSdkVersion 30
versionCode 2
versionName 'v1.0.1'
versionCode 3
versionName 'v1.0.2'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ final class DaynightContainer {
private final View root;
private final TextView title;
private final SingleContainer day, night;

public DaynightContainer(View view, int rootId) {
root = view.findViewById(rootId);

Expand All @@ -20,6 +21,16 @@ public DaynightContainer(View view, int rootId) {
night.getTitle().setText(R.string.info_daynight_night);
}

public String[] getDaynightStrings() {
return ((day.getContent().getText().length() == 0) &&
(night.getContent().getText().length() == 0)) ?
null :
new String[]{
day.getContent().getText().toString(),
night.getContent().getText().toString()
};
}

public View getRoot() {
return root;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,27 @@
import android.widget.Button;
import android.widget.TextView;

import java.util.Locale;

import ap.yadora.richadowonosas.fmdslst.R;
import ap.yadora.richadowonosas.fmdslst.song.SongInfo;

final class LocalizedContainer {
private final View root;
private final Button expandButton;
private final TextView title;
private final TextView title, contentTitle;
private final SingleContainer en, ja, zhHans, zhHant, ko;
private boolean isExpanded;
private int partsHeight, textHeight;
private final int HEIGHT_PARTS;
private int textHeight;
private final String defaultTitle;

public LocalizedContainer(View view, int rootId) {
root = view.findViewById(rootId);
HEIGHT_PARTS = (int) root.getResources().getDimension(R.dimen.height_parts);
partsHeight = 0;
textHeight = 0;
defaultTitle = root.getContext().getString(R.string.default_song_title);

title = root.findViewById(R.id.editTitleLocalized);
contentTitle = root.findViewById(R.id.contentTitle);
expandButton = root.findViewById(R.id.editButtonExpandLocalized);
en = new SingleContainer(root, R.id.editEn, SingleContainer.TYPE_MULTILINE_TEXT);
ja = new SingleContainer(root, R.id.editJa, SingleContainer.TYPE_MULTILINE_TEXT);
Expand All @@ -45,17 +48,30 @@ public LocalizedContainer(View view, int rootId) {
setHeight(zhHant.getRoot(), textHeight);
setHeight(ko.getRoot(), textHeight);

View.OnFocusChangeListener onFocusChangeListener = new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
refresh();
}
};
en.getContent().setOnFocusChangeListener(onFocusChangeListener);
ja.getContent().setOnFocusChangeListener(onFocusChangeListener);
zhHans.getContent().setOnFocusChangeListener(onFocusChangeListener);
zhHant.getContent().setOnFocusChangeListener(onFocusChangeListener);
ko.getContent().setOnFocusChangeListener(onFocusChangeListener);

expandButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isExpanded = !isExpanded;
if (isExpanded) {
expandButton.setText(R.string.selection_collapse);
partsHeight = HEIGHT_PARTS;
expandButton.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, root.getContext().getDrawable(R.drawable.icon_normal_expand), null);
textHeight = ViewGroup.LayoutParams.WRAP_CONTENT;
} else {
expandButton.setText(R.string.selection_expand);
partsHeight = textHeight = 0;
expandButton.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, root.getContext().getDrawable(R.drawable.icon_normal_collapse), null);
textHeight = 0;
}

setHeight(en.getRoot(), textHeight);
Expand All @@ -73,6 +89,61 @@ private void setHeight(View view, int height) {
view.setLayoutParams(layoutParams);
}

public void refresh() {
contentTitle.setText(getStringToShow());
}

public String[] getLocalizedStrings(boolean allowsNull) {
return (allowsNull &&
(en.getContent().getText().length() == 0) &&
(ja.getContent().getText().length() == 0) &&
(zhHans.getContent().getText().length() == 0) &&
(zhHant.getContent().getText().length() == 0) &&
(ko.getContent().getText().length() == 0)) ?
null :
new String[]{
en.getContent().getText().toString(),
(ja.getContent().getText().length() == 0) ? null : ja.getContent().getText().toString(),
(zhHans.getContent().getText().length() == 0) ? null : zhHans.getContent().getText().toString(),
(zhHant.getContent().getText().length() == 0) ? null : zhHant.getContent().getText().toString(),
(ko.getContent().getText().length() == 0) ? null : ko.getContent().getText().toString()
};
}

private String getStringToShow() {
String result = null;
String[] localizedStrings = getLocalizedStrings(true);
if (localizedStrings == null) {
return defaultTitle;
}

switch (Locale.getDefault().getLanguage()) {
case "zh":
if (Locale.getDefault().getCountry().equals("CN")) {
result = localizedStrings[SongInfo.LOCALIZED_ZH_HANS];
}
else {
result = localizedStrings[SongInfo.LOCALIZED_ZH_HANT];
}
break;
case "ko":
result = localizedStrings[SongInfo.LOCALIZED_KO];
break;
case "ja":
result = localizedStrings[SongInfo.LOCALIZED_JA];
break;
case "en":
result = localizedStrings[SongInfo.LOCALIZED_EN];
}
if (result == null) {
if ((result = localizedStrings[SongInfo.LOCALIZED_JA]) == null) {
result = localizedStrings[SongInfo.LOCALIZED_EN];
}
}

return result;
}

public View getRoot() {
return root;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void getInitialContentFromSongInfo(SongInfo single) {
titleLocalized.getZhHant().getContent().setText(titles[SongInfo.LOCALIZED_ZH_HANT]);
titleLocalized.getKo().getContent().setText(titles[SongInfo.LOCALIZED_KO]);
titleLocalized.getTitle().setText(R.string.info_title);
titleLocalized.refresh();
}
artist.getContent().setText(single.getArtist());
artist.getTitle().setText(R.string.info_artist);
Expand All @@ -92,6 +93,7 @@ public void getInitialContentFromSongInfo(SongInfo single) {
artistLocalized.getZhHant().getContent().setText(artists[SongInfo.LOCALIZED_ZH_HANT]);
artistLocalized.getKo().getContent().setText(artists[SongInfo.LOCALIZED_KO]);
artistLocalized.getTitle().setText(R.string.info_artist_localized);
artistLocalized.refresh();
}
bpm.getContent().setText(single.getBpm());
bpm.getTitle().setText(R.string.info_bpm);
Expand Down Expand Up @@ -145,6 +147,7 @@ public void onClick(View v) {
source.getZhHant().getContent().setText(sources[SongInfo.LOCALIZED_ZH_HANT]);
source.getKo().getContent().setText(sources[SongInfo.LOCALIZED_KO]);
source.getTitle().setText(R.string.info_source);
source.refresh();
}
sourceCopyright.getContent().setText(single.getSource_copyright());
sourceCopyright.getTitle().setText(R.string.info_source_copyright);
Expand Down Expand Up @@ -313,34 +316,9 @@ public void onFocusChange(View v, boolean hasFocus) {
public SongInfo getSongInfo() {
SongInfo single = new SongInfo();
single.setId(id.getContent().getText().toString());
single.setTitle_localized(SongInfo.getLocalizedFromStrings(
new String[]{
titleLocalized.getEn().getContent().getText().toString(),
(titleLocalized.getJa().getContent().getText().length() == 0) ? null : titleLocalized.getJa().getContent().getText().toString(),
(titleLocalized.getZhHans().getContent().getText().length() == 0) ? null : titleLocalized.getZhHans().getContent().getText().toString(),
(titleLocalized.getZhHant().getContent().getText().length() == 0) ? null : titleLocalized.getZhHant().getContent().getText().toString(),
(titleLocalized.getKo().getContent().getText().length() == 0) ? null : titleLocalized.getKo().getContent().getText().toString()
}
));
single.setTitle_localized(SongInfo.getLocalizedFromStrings(titleLocalized.getLocalizedStrings(false)));
single.setArtist(artist.getContent().getText().toString());
single.setArtist_localized(
(
(artistLocalized.getEn().getContent().getText().length() == 0) &&
(artistLocalized.getJa().getContent().getText().length() == 0) &&
(artistLocalized.getZhHans().getContent().getText().length() == 0) &&
(artistLocalized.getZhHant().getContent().getText().length() == 0) &&
(artistLocalized.getKo().getContent().getText().length() == 0)
) ?
null :
SongInfo.getLocalizedFromStrings(
new String[]{
artistLocalized.getEn().getContent().getText().toString(),
(artistLocalized.getJa().getContent().getText().length() == 0) ? null : titleLocalized.getJa().getContent().getText().toString(),
(artistLocalized.getZhHans().getContent().getText().length() == 0) ? null : titleLocalized.getZhHans().getContent().getText().toString(),
(artistLocalized.getZhHant().getContent().getText().length() == 0) ? null : titleLocalized.getZhHant().getContent().getText().toString(),
(artistLocalized.getKo().getContent().getText().length() == 0) ? null : titleLocalized.getKo().getContent().getText().toString()
})
);
single.setArtist_localized(SongInfo.getLocalizedFromStrings(artistLocalized.getLocalizedStrings(true)));
single.setBpm(bpm.getContent().getText().toString());
single.setBpm_base(new BigDecimal(bpmBase.getContent().getText().toString()).doubleValue());
single.setSet(set.getContent().getText().toString());
Expand All @@ -349,42 +327,15 @@ public SongInfo getSongInfo() {
single.setAudioPreviewEnd(new BigInteger(audioPreviewEnd.getContent().getText().toString()).intValue());
single.setSide(side.getSelected());
single.setBg(bg.getContent().getText().toString());
single.setBg_daynight(
(
(bgDaynight.getDay().getContent().getText().length() == 0) &&
(bgDaynight.getNight().getContent().getText().length() == 0)
) ?
null :
SongInfo.getDaynightFromStrings(
new String[]{
bgDaynight.getDay().getContent().getText().toString(),
bgDaynight.getNight().getContent().getText().toString()
})
);
single.setBg_daynight(SongInfo.getDaynightFromStrings(bgDaynight.getDaynightStrings()));
single.setDate(new BigInteger(date.getContent().getText().toString()).longValue());
single.setVersion(version.getContent().getText().toString());
single.setWorld_unlock(worldUnlock.getContent().isChecked());
single.setRemote_dl(remoteDl.getContent().isChecked());
single.setByd_local_unlock(bydLocalUnlock.getContent().isChecked());
single.setSonglist_hidden(songlistHidden.getContent().isChecked());
single.setNo_pp(noPP.getContent().isChecked());
single.setSource(
(
(source.getEn().getContent().getText().length() == 0) &&
(source.getJa().getContent().getText().length() == 0) &&
(source.getZhHans().getContent().getText().length() == 0) &&
(source.getZhHant().getContent().getText().length() == 0) &&
(source.getKo().getContent().getText().length() == 0)
) ?
null :
SongInfo.getLocalizedFromStrings(
new String[]{
source.getEn().getContent().getText().toString(),
(source.getJa().getContent().getText().length() == 0) ? null : titleLocalized.getJa().getContent().getText().toString(),
(source.getZhHans().getContent().getText().length() == 0) ? null : titleLocalized.getZhHans().getContent().getText().toString(),
(source.getZhHant().getContent().getText().length() == 0) ? null : titleLocalized.getZhHant().getContent().getText().toString(),
(source.getKo().getContent().getText().length() == 0) ? null : titleLocalized.getKo().getContent().getText().toString()
})
);
single.setSource(SongInfo.getLocalizedFromStrings(source.getLocalizedStrings(true)));
single.setSource_copyright((sourceCopyright.getContent().getText().length() == 0) ? null : sourceCopyright.getContent().getText().toString());
int cursor = -1;
for (int i = 0; i < 4; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ public static String[] getLocalizedStrings(Localized localized) {
}

public static Localized getLocalizedFromStrings(String[] localizedStrings) {
if (localizedStrings == null) {
return null;
}

Localized result = new Localized();

result.setEn((localizedStrings[LOCALIZED_EN] == null) ? "" : localizedStrings[LOCALIZED_EN]);
Expand All @@ -437,6 +441,9 @@ public String[] getDaynight() {
}

public static DayNight getDaynightFromStrings(String[] daynightString) {
if (daynightString == null) {
return null;
}
DayNight result = new DayNight();
result.setDay((daynightString[DAYNIGHT_DAY] == null) ? "" : daynightString[DAYNIGHT_DAY]);
result.setNight((daynightString[DAYNIGHT_NIGHT] == null) ? "" : daynightString[DAYNIGHT_NIGHT]);
Expand Down
27 changes: 21 additions & 6 deletions app/src/main/res/layout/content_edit_localized.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,28 @@
android:inputType="textPersonName"
android:orientation="vertical">

<Button
android:id="@+id/editButtonExpandLocalized"
<TableRow
android:layout_width="match_parent"
android:layout_height="45sp"
android:backgroundTint="@color/tairitsuLight"
android:minHeight="45sp"
android:textColor="@android:color/white" />
android:layout_height="match_parent" >

<TextView
android:id="@+id/contentTitle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="@string/default_song_title"
android:textColor="@color/tairitsuLight" />

<Button
android:id="@+id/editButtonExpandLocalized"
android:layout_width="wrap_content"
android:layout_height="45sp"
android:backgroundTint="@color/tairitsuLight"
android:drawableEnd="@drawable/icon_normal_collapse"
android:minHeight="45sp"
android:textColor="@android:color/white" />
</TableRow>

<include
android:id="@+id/editEn"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-ja-rJP/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<string name="selection_work_on_default">デフォルトのsonglistファイルを使う</string>
<string name="title_activity_select_song">曲を選んでください</string>
<string name="description_song_icon">当曲のカバーでございます。</string>
<string name="default_song_title">未知な曲</string>
<string name="default_song_title">未設定</string>
<string name="title_choose_operation">行動を選んでください</string>
<string name="selection_back">戻る</string>
<string name="selection_cancel">キャンセル</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<string name="content_start_scene_title">请选择要使用的songlist文件</string>
<string name="title_activity_select_song">请选择曲目</string>
<string name="description_song_icon">这是该曲目的封面。</string>
<string name="default_song_title">未知曲目</string>
<string name="default_song_title">未设定</string>
<string name="title_choose_operation">请选择操作</string>
<string name="selection_back">返回</string>
<string name="selection_save_and_exit">保存并返回</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<string name="error_explorer_not_found">There is no file explorer in your device!</string>
<string name="title_activity_select_song">Please select a song</string>
<string name="description_song_icon">This is the cover of this song</string>
<string name="default_song_title">Unknown</string>
<string name="default_song_title">Vacant</string>
<string name="default_song_id" translatable="false">(id: default)</string>
<string name="title_choose_operation">Please choose an operation</string>
<string name="selection_back">Back</string>
Expand Down

0 comments on commit dd5dc9c

Please sign in to comment.