Skip to content

Commit 7283701

Browse files
authored
Merge pull request TeamNewPipe#12978 from dustdfg/kotlin_merged
Conversion to kotlin of multiple files
2 parents 1fb2b4a + 3ffcf11 commit 7283701

39 files changed

+677
-963
lines changed

app/src/main/java/org/schabi/newpipe/error/UserAction.java renamed to app/src/main/java/org/schabi/newpipe/error/UserAction.kt

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
package org.schabi.newpipe.error;
1+
/*
2+
* SPDX-FileCopyrightText: 2017-2025 NewPipe contributors <https://newpipe.net>
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*/
5+
6+
package org.schabi.newpipe.error
27

38
/**
49
* The user actions that can cause an error.
510
*/
6-
public enum UserAction {
11+
enum class UserAction(val message: String) {
712
USER_REPORT("user report"),
813
UI_ERROR("ui error"),
914
DATABASE_IMPORT_EXPORT("database import or export"),
@@ -36,14 +41,4 @@ public enum UserAction {
3641
GETTING_MAIN_SCREEN_TAB("getting main screen tab"),
3742
PLAY_ON_POPUP("play on popup"),
3843
SUBSCRIPTIONS("loading subscriptions");
39-
40-
private final String message;
41-
42-
UserAction(final String message) {
43-
this.message = message;
44-
}
45-
46-
public String getMessage() {
47-
return message;
48-
}
4944
}

app/src/main/java/org/schabi/newpipe/fragments/list/search/SuggestionItem.java

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2017-2025 NewPipe contributors <https://newpipe.net>
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*/
5+
6+
package org.schabi.newpipe.fragments.list.search
7+
8+
class SuggestionItem(@JvmField val fromHistory: Boolean, @JvmField val query: String) {
9+
override fun equals(other: Any?): Boolean {
10+
if (other is SuggestionItem) {
11+
return query == other.query
12+
}
13+
return false
14+
}
15+
16+
override fun hashCode() = query.hashCode()
17+
18+
override fun toString() = "[$fromHistory$query]"
19+
}

app/src/main/java/org/schabi/newpipe/fragments/list/search/SuggestionListAdapter.java

Lines changed: 0 additions & 94 deletions
This file was deleted.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2017-2025 NewPipe contributors <https://newpipe.net>
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*/
5+
6+
package org.schabi.newpipe.fragments.list.search
7+
8+
import android.view.LayoutInflater
9+
import android.view.ViewGroup
10+
import androidx.recyclerview.widget.DiffUtil
11+
import androidx.recyclerview.widget.ListAdapter
12+
import androidx.recyclerview.widget.RecyclerView
13+
import org.schabi.newpipe.R
14+
import org.schabi.newpipe.databinding.ItemSearchSuggestionBinding
15+
import org.schabi.newpipe.fragments.list.search.SuggestionListAdapter.SuggestionItemHolder
16+
17+
class SuggestionListAdapter :
18+
ListAdapter<SuggestionItem, SuggestionItemHolder>(SuggestionItemCallback()) {
19+
20+
var listener: OnSuggestionItemSelected? = null
21+
22+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SuggestionItemHolder {
23+
return SuggestionItemHolder(
24+
ItemSearchSuggestionBinding.inflate(LayoutInflater.from(parent.context), parent, false)
25+
)
26+
}
27+
28+
override fun onBindViewHolder(holder: SuggestionItemHolder, position: Int) {
29+
val currentItem = getItem(position)
30+
holder.updateFrom(currentItem)
31+
holder.binding.suggestionSearch.setOnClickListener {
32+
listener?.onSuggestionItemSelected(currentItem)
33+
}
34+
holder.binding.suggestionSearch.setOnLongClickListener {
35+
listener?.onSuggestionItemLongClick(currentItem)
36+
true
37+
}
38+
holder.binding.suggestionInsert.setOnClickListener {
39+
listener?.onSuggestionItemInserted(currentItem)
40+
}
41+
}
42+
43+
interface OnSuggestionItemSelected {
44+
fun onSuggestionItemSelected(item: SuggestionItem)
45+
46+
fun onSuggestionItemInserted(item: SuggestionItem)
47+
48+
fun onSuggestionItemLongClick(item: SuggestionItem)
49+
}
50+
51+
class SuggestionItemHolder(val binding: ItemSearchSuggestionBinding) :
52+
RecyclerView.ViewHolder(binding.getRoot()) {
53+
fun updateFrom(item: SuggestionItem) {
54+
binding.itemSuggestionIcon.setImageResource(
55+
if (item.fromHistory) {
56+
R.drawable.ic_history
57+
} else {
58+
R.drawable.ic_search
59+
}
60+
)
61+
binding.itemSuggestionQuery.text = item.query
62+
}
63+
}
64+
65+
private class SuggestionItemCallback : DiffUtil.ItemCallback<SuggestionItem>() {
66+
override fun areItemsTheSame(oldItem: SuggestionItem, newItem: SuggestionItem): Boolean {
67+
return oldItem.fromHistory == newItem.fromHistory && oldItem.query == newItem.query
68+
}
69+
70+
override fun areContentsTheSame(oldItem: SuggestionItem, newItem: SuggestionItem): Boolean {
71+
return true // items' contents never change; the list of items themselves does
72+
}
73+
}
74+
}

app/src/main/java/org/schabi/newpipe/info_list/ItemViewMode.java renamed to app/src/main/java/org/schabi/newpipe/info_list/ItemViewMode.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
package org.schabi.newpipe.info_list;
1+
/*
2+
* SPDX-FileCopyrightText: 2023-2026 NewPipe contributors <https://newpipe.net>
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*/
5+
6+
package org.schabi.newpipe.info_list
27

38
/**
49
* Item view mode for streams & playlist listing screens.
510
*/
6-
public enum ItemViewMode {
11+
enum class ItemViewMode {
712
/**
813
* Default mode.
914
*/

app/src/main/java/org/schabi/newpipe/local/playlist/PlayListShareMode.java

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 NewPipe contributors <https://newpipe.net>
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*/
5+
6+
package org.schabi.newpipe.local.playlist
7+
8+
enum class PlayListShareMode {
9+
JUST_URLS,
10+
WITH_TITLES,
11+
YOUTUBE_TEMP_PLAYLIST
12+
}

app/src/main/java/org/schabi/newpipe/local/playlist/RemotePlaylistManager.java

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)