Skip to content

Commit

Permalink
Code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry08 committed Dec 23, 2022
1 parent 12037af commit 74c4d57
Show file tree
Hide file tree
Showing 29 changed files with 163 additions and 101 deletions.
72 changes: 72 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

[*.{cs,vb}]
#### Naming styles ####

# Naming rules

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Symbol specifications

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
end_of_line = crlf

[*.cs]
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
csharp_indent_labels = one_less_than_current
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = true:suggestion
1 change: 1 addition & 0 deletions AniStream.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AniStream", "AniStream\AniS
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B3DC27BF-3B60-4266-895D-9153C1825E19}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
README.md = README.md
EndProjectSection
EndProject
Expand Down
1 change: 0 additions & 1 deletion AniStream/Adapters/AnimeRecyclerAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public MyViewHolder(View view) : base(view)
public override int ItemCount => Animes.Count;

public override long GetItemId(int position) => position;


public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
Expand Down
4 changes: 2 additions & 2 deletions AniStream/Adapters/EpisodeRecyclerAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class EpisodeViewHolder : RecyclerView.ViewHolder
public TextView EpisodeNumber = default!;
public ProgressBar WatchedProgress = default!;

public EpisodeViewHolder(View view) : base (view)
public EpisodeViewHolder(View view) : base(view)
{
CardView = view.FindViewById<CardView>(Resource.Id.cardView)!;
EpisodeNumber = view.FindViewById<TextView>(Resource.Id.episodeNumber)!;
Expand All @@ -49,7 +49,7 @@ public EpisodeViewHolder(View view) : base (view)

public override int ItemCount => Episodes.Count;

public override long GetItemId(int position)=> position;
public override long GetItemId(int position) => position;

public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
Expand Down
5 changes: 2 additions & 3 deletions AniStream/Adapters/ExtractorAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class StreamViewHolder : RecyclerView.ViewHolder
public TextView streamName = default!;
public RecyclerView streamRecyclerView = default!;

public StreamViewHolder(View view) : base (view)
public StreamViewHolder(View view) : base(view)
{
streamName = view.FindViewById<TextView>(Resource.Id.streamName)!;
streamRecyclerView = view.FindViewById<RecyclerView>(Resource.Id.streamRecyclerView)!;
Expand All @@ -55,8 +55,7 @@ public StreamViewHolder(View view) : base (view)

public override int ItemCount => Containers.Count;

public override long GetItemId(int position)=> position;

public override long GetItemId(int position) => position;

public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
Expand Down
9 changes: 3 additions & 6 deletions AniStream/Adapters/VideoAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class UrlViewHolder : RecyclerView.ViewHolder
public TextView urlSize = default!;
public ImageButton urlDownload = default!;

public UrlViewHolder(View view) : base (view)
public UrlViewHolder(View view) : base(view)
{
urlQuality = view.FindViewById<TextView>(Resource.Id.urlQuality)!;
urlNote = view.FindViewById<TextView>(Resource.Id.urlNote)!;
Expand All @@ -48,7 +48,7 @@ public UrlViewHolder(View view) : base (view)

public override int ItemCount => Videos.Count;

public override long GetItemId(int position)=> position;
public override long GetItemId(int position) => position;

public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
Expand Down Expand Up @@ -76,12 +76,9 @@ public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int positi
{
var androidStoragePermission = new AndroidStoragePermission(_activity);

bool hasStoragePermission = androidStoragePermission.HasStoragePermission();
var hasStoragePermission = androidStoragePermission.HasStoragePermission();
if (!hasStoragePermission)
{
_activity.ShowToast("Please grant storage permission then retry");
hasStoragePermission = await androidStoragePermission.RequestStoragePermission();
}

if (!hasStoragePermission)
return;
Expand Down
3 changes: 1 addition & 2 deletions AniStream/Adapters/ViewPagerAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@ public ViewPagerAdapter(FragmentManager fm) : base(fm)

public override Fragment GetItem(int position) => Fragments[position];

public override int GetItemPosition(Java.Lang.Object @object)=> base.GetItemPosition(@object);

public override int GetItemPosition(Java.Lang.Object @object) => base.GetItemPosition(@object);
}
4 changes: 4 additions & 0 deletions AniStream/AniStream.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@
<PackageReference Include="Xamarin.Essentials" Version="1.7.3" />
<!--<PackageReference Include="Xamarin.Google.Guava" Version="31.1.0.3" />-->
</ItemGroup>

<ItemGroup>
<EditorConfigFiles Remove="C:\Users\jerem\source\repos\Xamarin Projects\AniStream\AniStream\.editorconfig" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion AniStream/BookmarksActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public override bool OnCreateOptionsMenu(IMenu? menu)

public override bool OnOptionsItemSelected(IMenuItem item)
{
int id = item.ItemId;
var id = item.ItemId;

if (id == Resource.Id.settings)
{
Expand Down
2 changes: 1 addition & 1 deletion AniStream/BroadcastReceivers/NetworkStateReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override void OnReceive(Context? context, Intent? intent)

private void NotifyStateToAll()
{
foreach (INetworkStateReceiverListener listener in listeners)
foreach (var listener in listeners)
NotifyState(listener);
}

Expand Down
12 changes: 6 additions & 6 deletions AniStream/EpisodesActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class EpisodesActivity : AppCompatActivity
protected override async void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);

SetContentView(Resource.Layout.animeinfo);

FirebaseApp.InitializeApp(this);
Expand All @@ -70,7 +70,7 @@ protected override async void OnCreate(Bundle? savedInstanceState)
var animeString = Intent?.GetStringExtra("anime");
if (!string.IsNullOrEmpty(animeString))
Anime = JsonConvert.DeserializeObject<Anime>(animeString)!;

var animeInfoTitle = FindViewById<TextView>(Resource.Id.animeInfoTitle)!;
var type = FindViewById<TextView>(Resource.Id.animeInfoType)!;
var genresFlowLayout = FindViewById<FlowLayout>(Resource.Id.flowLayout)!;
Expand All @@ -88,7 +88,7 @@ protected override async void OnCreate(Bundle? savedInstanceState)
// new BackPressedCallback(true, (s, e) => { }));
//
//OnBackPressedDispatcher.OnBackPressed();

back.Click += (s, e) => { OnBackPressedDispatcher.OnBackPressed(); };

menu.Click += (s, e) =>
Expand Down Expand Up @@ -276,7 +276,7 @@ private void PopupMenu_MenuItemClick(object? sender, PopupMenu.MenuItemClickEven

builder.SetCancelable(true);
//Dialog dialog = builder.Create();
AlertDialog dialog = builder.Create();
var dialog = builder.Create();
dialog.SetCanceledOnTouchOutside(true);

dialog.Show();
Expand Down Expand Up @@ -343,7 +343,7 @@ public override void OnRequestPermissionsResult(int requestCode, string[] permis
case 1:
{
// If request is cancelled, the result arrays are empty.
if (grantResults.Length > 0
if (grantResults.Length > 0
&& grantResults[0] == Permission.Granted)
{
//ContinueInitialize();
Expand All @@ -352,7 +352,7 @@ public override void OnRequestPermissionsResult(int requestCode, string[] permis
else
{
//Toast.makeText(MainActivity.this, "Permission denied to read your External storage", Toast.LENGTH_SHORT).show();

//Finish();
}
}
Expand Down
10 changes: 5 additions & 5 deletions AniStream/Fragments/AnimeFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public AnimeFragment(SearchFilter searchFilter)

public static AnimeFragment NewInstance(SearchFilter searchFilter)
{
Bundle bundle = new Bundle();
var bundle = new Bundle();
bundle.PutInt("searchFilter", (int)searchFilter);
AnimeFragment fragment = new AnimeFragment(searchFilter);
var fragment = new AnimeFragment(searchFilter);
fragment.Arguments = bundle;
return fragment;
}
Expand All @@ -54,7 +54,7 @@ public override View OnCreateView(LayoutInflater? inflater, ViewGroup? container
{
view = inflater?.Inflate(Resource.Layout.dublayout, container, false)!;
swipeRefreshLayout = view.FindViewById<SwipeRefreshLayout>(Resource.Id.swiperefresh)!;
RecyclerView mRecyclerView = view.FindViewById<RecyclerView>(Resource.Id.act_recyclerview)!;
var mRecyclerView = view.FindViewById<RecyclerView>(Resource.Id.act_recyclerview)!;
RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(view.Context, 2);
mRecyclerView.SetLayoutManager(mLayoutManager);

Expand All @@ -79,8 +79,8 @@ public override View OnCreateView(LayoutInflater? inflater, ViewGroup? container

if (mRecyclerView.GetAdapter() is AnimeRecyclerAdapter animeRecyclerAdapter)
{
int positionStart = animeRecyclerAdapter.Animes.Count;
int itemCount = animeRecyclerAdapter.Animes.Count;
var positionStart = animeRecyclerAdapter.Animes.Count;
var itemCount = animeRecyclerAdapter.Animes.Count;

animeRecyclerAdapter.Animes.RemoveAll(x => x.Id == "-1");

Expand Down
8 changes: 4 additions & 4 deletions AniStream/Fragments/SelectorDialogFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal class SelectorDialogFragment : BottomSheetDialogFragment
_anime = anime;
}

public static SelectorDialogFragment NewInstance(Anime anime, Episode episode, VideoActivity? videoActivity = null)
public static SelectorDialogFragment NewInstance(Anime anime, Episode episode, VideoActivity? videoActivity = null)
=> new(anime, episode, videoActivity);

public override void OnStart()
Expand All @@ -55,7 +55,7 @@ public override View OnCreateView(LayoutInflater inflater, ViewGroup? container,
_view = inflater.Inflate(Resource.Layout.bottom_sheet_selector, container, false)!;
var autoLayout = _view.FindViewById<LinearLayout>(Resource.Id.selectorAutoListContainer);
var layout = _view.FindViewById<LinearLayout>(Resource.Id.selectorListContainer);

var selectorMakeDefault = _view.FindViewById<CheckBox>(Resource.Id.selectorMakeDefault)!;
var serversRecyclerView = _view.FindViewById<RecyclerView>(Resource.Id.selectorRecyclerView)!;
var selectorProgressBar = _view.FindViewById<ProgressBar>(Resource.Id.selectorProgressBar)!;
Expand All @@ -69,7 +69,7 @@ public override View OnCreateView(LayoutInflater inflater, ViewGroup? container,
{
cache = new();

int totalServersLoaded = 0;
var totalServersLoaded = 0;

_client.OnVideoServersLoaded += (s, e) =>
{
Expand Down Expand Up @@ -168,7 +168,7 @@ public override View OnCreateView(LayoutInflater inflater, ViewGroup? container,
}
else
{
int totalServersLoaded = 0;
var totalServersLoaded = 0;

var adapter = new ExtractorAdapter(activity, _anime, _episode,
cache.Where(x => x.IsLoaded && x.Videos.Count > 0).ToList());
Expand Down
14 changes: 6 additions & 8 deletions AniStream/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected override async void OnCreate(Bundle? savedInstanceState)

if (!WeebUtils.HasNetworkConnection(this))
{
Android.Widget.LinearLayout linearLayout1 = FindViewById<Android.Widget.LinearLayout>(Resource.Id.notvisiblelinearlayout)!;
var linearLayout1 = FindViewById<Android.Widget.LinearLayout>(Resource.Id.notvisiblelinearlayout)!;
linearLayout1.Visibility = ViewStates.Visible;
viewPager.Visibility = ViewStates.Gone;

Expand All @@ -88,7 +88,7 @@ protected override async void OnCreate(Bundle? savedInstanceState)
var animeSiteStr = await SecureStorage.GetAsync("AnimeSite");
if (!string.IsNullOrEmpty(animeSiteStr))
WeebUtils.AnimeSite = (AnimeSites)Convert.ToInt32(animeSiteStr);

_client = new(WeebUtils.AnimeSite);
_client.OnAnimesLoaded += Client_OnAnimesLoaded;

Expand Down Expand Up @@ -317,7 +317,7 @@ private void SetupSources(IMenu menu)

public override bool OnOptionsItemSelected(IMenuItem item)
{
int id = item.ItemId;
var id = item.ItemId;

if (id == Resource.Id.settings)
{
Expand All @@ -336,7 +336,7 @@ public override bool OnOptionsItemSelected(IMenuItem item)
var i = new Intent(this, typeof(BookmarksActivity));
StartActivity(i);
OverridePendingTransition(Resource.Animation.anim_slide_in_left, Resource.Animation.anim_slide_out_left);

return false;
}
else if (id == Resource.Id.donate)
Expand All @@ -347,13 +347,13 @@ public override bool OnOptionsItemSelected(IMenuItem item)
}
else
SaveSelectedSource(id);

return base.OnOptionsItemSelected(item);
}

private async void SaveSelectedSource(int id)
{
bool shouldUpdateMainView = false;
var shouldUpdateMainView = false;

var lastAnimeSite = WeebUtils.AnimeSite;

Expand Down Expand Up @@ -383,12 +383,10 @@ public override void OverridePendingTransition(int enterAnim, int exitAnim)

public void OnPageScrollStateChanged(int state)
{

}

public void OnPageScrolled(int position, float positionOffset, int positionOffsetPixels)
{

}

public void OnPageSelected(int position)
Expand Down
Loading

0 comments on commit 74c4d57

Please sign in to comment.